Re: More questions on realloc
- From: Mark McIntyre <markmcintyre@xxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 17:31:43 +0000
On Tue, 29 Nov 2005 17:27:48 GMT, in comp.lang.c , Robert Harris
<robert.f.harris@xxxxxxxxxxxxxxxx> wrote:
>Mark McIntyre wrote:
>> On Tue, 29 Nov 2005 17:01:17 GMT, in comp.lang.c , "James S.
>> Singleton" <pt109@xxxxxxxxxx> wrote:
>>
>>>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?
>>
>But realloc doesn't always have to reallocate memory; if you malloc,
>say, 10 bytes, you may well actually get 32 (or 1024) bytes.
This is sometimes true, but not relevant to the OP since
a) you don't know if your compiler can do this and
b) you don't know if it did, in any specific case and
c) it may in any events not be able to, in any specific case.
Whatever, realloc can under the hood operate however it likes,
provided it behaves *as if* it had done a new *alloc, copy and free.
--
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 =----
.
- References:
- More questions on realloc
- From: James S. Singleton
- Re: More questions on realloc
- From: Mark McIntyre
- Re: More questions on realloc
- From: Robert Harris
- More questions on realloc
- Prev by Date: Re: More questions on realloc
- Next by Date: Re: Advanced C
- Previous by thread: Re: More questions on realloc
- Next by thread: Re: More questions on realloc
- Index(es):
Relevant Pages
|