This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: realloc without moving?
- From: Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>
- To: caj at cs dot york dot ac dot uk, libc-alpha at sources dot redhat dot com
- Date: 29 Oct 2004 08:52:08 -0000
- Subject: Re: realloc without moving?
- References: <418163A8.9040003@cs.york.ac.uk> <41816A2D.7050203@redhat.com>
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.