This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: timeline?


Thomas Breuel wrote:
Just to make sure we're on the same page; after

p = malloc(1000000000);

the following statement

p = realloc(p,1000000000+10000);

involves no copying of data; it's about as fast as p=malloc(10000);

There is no guarantee of this. Yes, realloc() tries to avoid copying, but it's not always possible.


Unless your point is that in the libc allocator on your system, 1000000000 is over the mmap threshold, in which case your statement holds.

As an aside,

p = realloc(p, ...)

is a bad idea, since if realloc() fails, p is set to NULL and you have leaked the memory where p was originally pointing.

Are you saying that a = [a,1] actually uses realloc internally?

Even with MOVE_ALLOC, if you try to do the same thing, you end up
making one copy.

IIRC both of these use realloc behind the covers.



-- Janne Blomqvist


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]