R
ranjeet.gupta
Dear All
As I was going through the Recent replies on the realloc(),
I got some question and my annalysis on that, so regarding on these
please guide me where I fail on the theoritical and practical
Knowledge. I am not able to read all the thread in the replies as
due to some problem in the web server.
Point 1.
If we do the realloc then it means that we have allocated the
extended memory for the current memory, for which we have
reallocated it. Means I need not to free the previous memory
which I extendend to realloc if compiler allocates memory
(extended memory) from the place where intial memory was allocated.
And we need to free if the memory is allocated by the
(realloc)in the new region.
so the key is to always free the memory when you reallocate
the memory by realloc fucntion.
How much I am correct on the Point 1 ?
Point 2.
what is the diffrence between the calloc() and malloc()
As far As I know the basic diffrence is that
1. malloc takes 1 argumnets while calloc takes two
2. malloc initialise the memory with the garbage values while
calloc initialise it with 0 (Zero)
3. malloc allocates continious memeory i.e one Block while
calloc alloactes into the Block
calloc (100, 2) ,means two block of 100 memoty alloaction.
apart from the above is any more diffrence between them ??
Point 3.
This may be looks off topic to you but I have one thing to ask
is there any diffrence between the malloc and new ??
Point 4.
why we need to derefrence the pointers once we are are done with our
work; I am not aware of garbage collection, And where I can find the
memory leak into the program ?
Thanks In Advance
Regards
Ranjeet
As I was going through the Recent replies on the realloc(),
I got some question and my annalysis on that, so regarding on these
please guide me where I fail on the theoritical and practical
Knowledge. I am not able to read all the thread in the replies as
due to some problem in the web server.
Point 1.
If we do the realloc then it means that we have allocated the
extended memory for the current memory, for which we have
reallocated it. Means I need not to free the previous memory
which I extendend to realloc if compiler allocates memory
(extended memory) from the place where intial memory was allocated.
And we need to free if the memory is allocated by the
(realloc)in the new region.
so the key is to always free the memory when you reallocate
the memory by realloc fucntion.
How much I am correct on the Point 1 ?
Point 2.
what is the diffrence between the calloc() and malloc()
As far As I know the basic diffrence is that
1. malloc takes 1 argumnets while calloc takes two
2. malloc initialise the memory with the garbage values while
calloc initialise it with 0 (Zero)
3. malloc allocates continious memeory i.e one Block while
calloc alloactes into the Block
calloc (100, 2) ,means two block of 100 memoty alloaction.
apart from the above is any more diffrence between them ??
Point 3.
This may be looks off topic to you but I have one thing to ask
is there any diffrence between the malloc and new ??
Point 4.
why we need to derefrence the pointers once we are are done with our
work; I am not aware of garbage collection, And where I can find the
memory leak into the program ?
Thanks In Advance
Regards
Ranjeet