Re: More questions on realloc
- From: Mark McIntyre <markmcintyre@xxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 17:13:45 +0000
On Tue, 29 Nov 2005 17:01:17 GMT, in comp.lang.c , "James S.
Singleton" <pt109@xxxxxxxxxx> wrote:
> My question is, how does realloc know that p points to a memory region
>size1 bytes in length?
By magic.
Seriously, this is an implementation detail that the end user doesn't
actually need to know. Under the hood it might be doing all sorts of
things (a lookup table of malloced blocks and their sizes, storing the
size in memor just before the malloced block, etc etc. But you don't
need to know - it just works.
>Or, to put it differently, can realloc be
>implemented with malloc, and no other memory management call?
You'd need memcpy and free. How else can you copy the memory from the
old to the new pointers, and then free the old one?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.
- Follow-Ups:
- Re: More questions on realloc
- From: Robert Harris
- Re: More questions on realloc
- References:
- More questions on realloc
- From: James S. Singleton
- More questions on realloc
- Prev by Date: Re: Advanced C
- Next by Date: Re: More questions on realloc
- Previous by thread: More questions on realloc
- Next by thread: Re: More questions on realloc
- Index(es):