Search the web
Sign In
New User? Sign Up
autotrace
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Dynamic arrays   Message List  
Reply | Forward Message #1188 of 1209 |
Re: [AutoTrace] Re: Dynamic arrays

> Can we do something similar in pure C without using that lib? Some
> simple example code?

I can do nothing with pure C :-P

Here is the code from glib/glib/garray.c:
static void
g_array_maybe_expand (GRealArray *array,
gint len)
{
guint want_alloc = g_array_elt_len (array, array->len + len +
array->zero_terminated);

if (want_alloc > array->alloc)
{
want_alloc = g_nearest_pow (want_alloc);
want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);

array->data = g_realloc (array->data, want_alloc);

#ifdef ENABLE_GC_FRIENDLY
memset (array->data + array->alloc, 0, want_alloc - array->alloc);
#endif /* ENABLE_GC_FRIENDLY */

array->alloc = want_alloc;
}
}



Mon Oct 23, 2006 9:25 am

jet@...
Send Email Send Email

Forward
Message #1188 of 1209 |
Expand Messages Author Sort by Date

I am looking for a better way creating dynamic arrays in C. I have the following problem. First I create an array with the size 1 then I resized it to size 2...
martweb2000
Offline Send Email
Oct 23, 2006
7:22 am

Hi, ... If you allocated n byte with realloc last time and you need n+1 or more, allocate 2*n with realloc. realloc already does so? STL does something more...
Masatake YAMATO
jet@...
Send Email
Oct 23, 2006
8:35 am

Can we do something similar in pure C without using that lib? Some simple example code? ... have the ... know ... very ... more,...
martweb2000
Offline Send Email
Oct 23, 2006
8:45 am

... I can do nothing with pure C :-P Here is the code from glib/glib/garray.c: static void g_array_maybe_expand (GRealArray *array, gint len) { guint...
Masatake YAMATO
jet@...
Send Email
Oct 23, 2006
9:30 am

What is faster - using the glib or stl? ... Some...
martweb2000
Offline Send Email
Oct 23, 2006
10:14 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help