Re: More questions on realloc - Thanks
- From: "David Resnick" <lndresnick@xxxxxxxxx>
- Date: 29 Nov 2005 11:12:54 -0800
Skarmander wrote:
> David Resnick wrote:
> > 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.
> >
> How do you copy memory if you don't know the size of the old region? There
> is no way to implement realloc(ptr, size) as a separate function, without
> access to the internal memory management structures. If you think otherwise,
> please supply the code. I have a feeling you're talking about something else
> entirely, but it's unclear what.
You are being charitable assuming I'm talking about something else,
I was just wrong.
-David
.
- References:
- More questions on realloc - Thanks
- From: James S. Singleton
- Re: More questions on realloc - Thanks
- From: David Resnick
- Re: More questions on realloc - Thanks
- From: Skarmander
- More questions on realloc - Thanks
- Prev by Date: Re: direct string manuplation not working
- Next by Date: Re: What is the use of Function Pointers in C language?
- Previous by thread: Re: More questions on realloc - Thanks
- Next by thread: Re: More questions on realloc - Thanks
- Index(es):
Relevant Pages
|