S
s.subbarayan
Dear all,
I happen to come across this exciting inspiring article regarding
memory leaks in this website:
http://www.embedded.com/story/OEG20020222S0026
In this article the author mentions:
"At a certain point in the code you may be unsure if a particular
block is no longer needed. If you free() this piece of memory, but
continue to access it (probably via a second pointer to the same
memory), your program may function perfectly until that particular
piece of memory is reallocated to another part of the program. Then
two different parts of the program will proceed to write over each
other's data. If you decide to not free the memory, on the grounds
that it may still be in use, then you may not get another opportunity
to free it (since all pointers to the block may have gone out of scope
or been reassigned to point elsewhere). In this case the program logic
will not be affected. But if the piece of code that leaks memory is
visited on a regular basis, the leak will tend towards infinity, as
the execution time of the program increases. "
I am not able to be clear on the second sentence:
"If you free() this piece of memory, but continue to access it
(probably via a second pointer to the same memory), your program may
function perfectly until that particular piece of memory is
reallocated to another part of the program."
I am also not able to get "the pointers to go out of scope" if I dont
free the memory as mentioned in the above paragraph?Can some one
enlight me on this?
My question is how can you free a memory and access it with second
pointer?My understanding was when I do malloc,I get exclusive access
to that piece of memory and unless I free it,its not available to some
one.If my understanding is correct,I dont see a way where a second
pointer can access it.I mean to say that my understanding is when
memory is allocated via malloc,the pointer returned is exclusively
accessing that place.How can some other pointer get a chance to point
to same location(unless the programmer explicitly comes to know the
address and assigns to a pointer)?
Even some time bak on MARCH 8th exactly,to my query on dynamic
allocation,some experts have voiced the same views said in this
article(google for "subbarayan" with in this group and u will get my
query).
It will be helpful if someone can make this clear to me so that I can
be careful while developing memory constraint applications.
Looking faward for all your replys and advanced thanks for the same,
Regards,
s.subbarayan
I happen to come across this exciting inspiring article regarding
memory leaks in this website:
http://www.embedded.com/story/OEG20020222S0026
In this article the author mentions:
"At a certain point in the code you may be unsure if a particular
block is no longer needed. If you free() this piece of memory, but
continue to access it (probably via a second pointer to the same
memory), your program may function perfectly until that particular
piece of memory is reallocated to another part of the program. Then
two different parts of the program will proceed to write over each
other's data. If you decide to not free the memory, on the grounds
that it may still be in use, then you may not get another opportunity
to free it (since all pointers to the block may have gone out of scope
or been reassigned to point elsewhere). In this case the program logic
will not be affected. But if the piece of code that leaks memory is
visited on a regular basis, the leak will tend towards infinity, as
the execution time of the program increases. "
I am not able to be clear on the second sentence:
"If you free() this piece of memory, but continue to access it
(probably via a second pointer to the same memory), your program may
function perfectly until that particular piece of memory is
reallocated to another part of the program."
I am also not able to get "the pointers to go out of scope" if I dont
free the memory as mentioned in the above paragraph?Can some one
enlight me on this?
My question is how can you free a memory and access it with second
pointer?My understanding was when I do malloc,I get exclusive access
to that piece of memory and unless I free it,its not available to some
one.If my understanding is correct,I dont see a way where a second
pointer can access it.I mean to say that my understanding is when
memory is allocated via malloc,the pointer returned is exclusively
accessing that place.How can some other pointer get a chance to point
to same location(unless the programmer explicitly comes to know the
address and assigns to a pointer)?
Even some time bak on MARCH 8th exactly,to my query on dynamic
allocation,some experts have voiced the same views said in this
article(google for "subbarayan" with in this group and u will get my
query).
It will be helpful if someone can make this clear to me so that I can
be careful while developing memory constraint applications.
Looking faward for all your replys and advanced thanks for the same,
Regards,
s.subbarayan