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

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

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 #1185 of 1209 |
Re: [AutoTrace] Dynamic arrays

Hi,

> 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 then to size 3 ... always by one as I do not know
> the final size. For size I use realloc, but doing it such way is very
> slow. Any better idea in C?

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 clever?

Masatake



Mon Oct 23, 2006 8:24 am

jet@...
Send Email Send Email

Forward
Message #1185 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