By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

how the realloc( ) allocates memory ?

P: n/a
is there any difference in how the realloc() reallocates memory to
varibles which were being allocated memory using malloc() and calloc ?
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
M a n i s h <ma***********@yahoo.com> 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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"We sorcerers don't like to eat our words, so to say."
- Sparrowhawk
Nov 13 '05 #2

P: n/a
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
M a n i s h <ma***********@yahoo.com> 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) fl***@barrow.com
Nov 13 '05 #3

P: n/a
ma***********@yahoo.com (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
Nov 13 '05 #4

P: n/a
On Fri, 21 Nov 2003 00:59:54 -0900, Floyd Davidson wrote:
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
M a n i s h <ma***********@yahoo.com> 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

Nov 13 '05 #5

P: n/a
> Is that really true, in respect to what the OP is asking?

I suppose OP stands for Original Poster.
Nov 13 '05 #6

P: n/a
"Vijay Kumar R Zanvar" <vi*****@hotpop.com> 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) fl***@barrow.com
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.