realloc without moving?
Wolfram Gloger
wmglo@dent.med.uni-muenchen.de
Fri Oct 29 09:06:00 GMT 2004
chris wrote:
>
> > Is there a function in glibc like realloc, except in the case where it
> > is not possible to extend the existing memory then instead of allocating
> > a new block of memory and copying the old block into this area the
> > function simply returns?
Uli wrote:
> There is not code like this. You can query in glibc's implementation
> the actual maximum block size with malloc_usable_size() although I don't
> know whether this works in all situations. It simply never has been
> used much.
I can confirm that malloc_usable_size() is supposed to work in all
situations -- if it wouldn't work I'd consider it a bug.
However, I think malloc_usable_size will not help that much for the
realloc() decision described above. malloc_usable_size is usually not
much larger than the chunk size originally requested (typically just a
few bytes), and it definitely does not account for a following,
available chunk. So, despite malloc_usable_size telling you "not
enough memory in this chunk available", a realloc to some larger size
might actually succeed anyway, without changing the chunk address.
To Chris: What exactly are your requirements? You are aware that
glibc on Linux also has efficient realloc for very large chunks thanks
to the mremap() system call?
Regards,
Wolfram.
More information about the Libc-alpha
mailing list