Re: More questions on realloc - Thanks
- From: "David Resnick" <lndresnick@xxxxxxxxx>
- Date: 29 Nov 2005 10:35:53 -0800
James S. Singleton wrote:
> Thanks everybody for your replies. I gather that:
> b) Implementing realloc(ptr, size) using malloc(), memcpy() and free()
> alone, without knowing the size of the memory region pointed to by ptr, is
> just not possible.
Sure it is possible. Just inefficient. You can malloc a new
space, free the old (if malloc succeeds), and copy on all calls
to realloc. What you lose is the ability to reuse the existing space
in cases where the new size is <= the old, or in cases where there
is additional free space after the current block. Which is likely a
less than optimal way to do things, but could be good enough.
-David
.
- Follow-Ups:
- Re: More questions on realloc - Thanks
- From: Skarmander
- Re: More questions on realloc - Thanks
- References:
- More questions on realloc - Thanks
- From: James S. Singleton
- More questions on realloc - Thanks
- Prev by Date: More questions on realloc - Thanks
- Next by Date: PayPal Opportunity
- Previous by thread: More questions on realloc - Thanks
- Next by thread: Re: More questions on realloc - Thanks
- Index(es):
Relevant Pages
|