Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how the realloc( ) allocates memory ?

Reply
Thread Tools

how the realloc( ) allocates memory ?

 
 
M a n i s h
Guest
Posts: n/a
 
      11-21-2003
is there any difference in how the realloc() reallocates memory to
varibles which were being allocated memory using malloc() and calloc ?
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      11-21-2003
M a n i s h <(E-Mail Removed)> scribbled the following:
> is there any difference in how the realloc() reallocates memory to
> varibles which were being allocated memory using malloc() and calloc ?


This would have to be an implementation-specific detail.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"We sorcerers don't like to eat our words, so to say."
- Sparrowhawk
 
Reply With Quote
 
 
 
 
Floyd Davidson
Guest
Posts: n/a
 
      11-21-2003
Joona I Palaste <(E-Mail Removed)> wrote:
>M a n i s h <(E-Mail Removed)> scribbled the following:
>> is there any difference in how the realloc() reallocates memory to
>> varibles which were being allocated memory using malloc() and calloc ?

>
>This would have to be an implementation-specific detail.


Is that really true, in respect to what the OP is asking?

The realloc, calloc and malloc functions all perform "magic"
behind the scenes, and the details are not available to the
programmer. But outwardly, "magic" is spelled the same for all
three.

Both the realloc and free functions can operate on a pointer
returned by any of the three. I think that is what the OP
probably meant by "is there any difference", and for the
programmer the answer is no, they are the same.

Of course, underneath they might accomplish "magic" in three
distinct ways... but that is of concern only to the implementor.

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      11-21-2003
(E-Mail Removed) (M a n i s h) wrote:

> is there any difference in how the realloc() reallocates memory to
> varibles which were being allocated memory using malloc() and calloc ?


Internally, no idea. But it doesn't matter, since the effect is
identical - you are either given a pointer to the new memory, or a null
pointer.

Richard
 
Reply With Quote
 
Nils Petter Vaskinn
Guest
Posts: n/a
 
      11-21-2003
On Fri, 21 Nov 2003 00:59:54 -0900, Floyd Davidson wrote:

> Joona I Palaste <(E-Mail Removed)> wrote:
>>M a n i s h <(E-Mail Removed)> scribbled the following:
>>> is there any difference in how the realloc() reallocates memory to
>>> varibles which were being allocated memory using malloc() and calloc ?

>>
>>This would have to be an implementation-specific detail.

>
> Is that really true, in respect to what the OP is asking?
>
> The realloc, calloc and malloc functions all perform "magic"
> behind the scenes, and the details are not available to the
> programmer. But outwardly, "magic" is spelled the same for all
> three.
>
> Both the realloc and free functions can operate on a pointer
> returned by any of the three. I think that is what the OP
> probably meant by "is there any difference", and for the
> programmer the answer is no, they are the same.
>
> Of course, underneath they might accomplish "magic" in three
> distinct ways... but that is of concern only to the implementor.


I think what the OP was interested in may have been:

Q: Does realloc treat a pointer to calloced memory different from malloced
memory, will the "new part" of a calloced array that grows be zeroed?

A: An implementation could do this, but the standard doesn't say it
should, so for portable code you can't depend on it.

OP:
You could write your own clearing realloc (crealloc?) like this:

crealloc (void *,size_t new_size, size_t current_size)

That calls realloc behind the scene and then memsets the new portion of
the array.



--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up

 
Reply With Quote
 
Vijay Kumar R Zanvar
Guest
Posts: n/a
 
      11-21-2003
> Is that really true, in respect to what the OP is asking?

I suppose OP stands for Original Poster.


 
Reply With Quote
 
Floyd Davidson
Guest
Posts: n/a
 
      11-21-2003
"Vijay Kumar R Zanvar" <(E-Mail Removed)> wrote:
>> Is that really true, in respect to what the OP is asking?

>
>I suppose OP stands for Original Poster.


Yes.

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
allocates something in one dll and then deallocates it in main exe DDD C++ 3 07-22-2009 09:30 AM
Macro that allocates storage and "returns" value Asbjørn Sæbø C Programming 12 01-11-2008 10:17 AM
Any other company than Sipgate that allocates local UK numbers Unknown Artist UK VOIP 5 01-08-2006 05:24 PM
Differences between Sony Memory Stick & memory Stick Pro vs Memory Stick Duo? zxcvar Digital Photography 3 11-28-2004 10:48 PM



Advertisments