Does malloc() reuse addresses?
- From: "avasilev" <alxvasilev@xxxxxxxxx>
- Date: 14 Jul 2006 11:48:15 -0700
Hi all,
my question is:
if i allocate some memory with malloc() and later free it (using
free()), is there a possibility that a consequent malloc() will
allocate memort at the same starting address and will return the same
pointer as the previous malloc(). I would like to have confirmation on
whether this is practically a concern when pointers are used to
uniquely identify data structure instances - like in this example:
int isInstanceValid(myStrict* inst)
{
int i;
for (i=0; i<instCount; ++i)
if (instances[i] == inst)
return 1;
return 0;
}
In this example, if an instance is freed, and a pointer to it becomes
non-valid, and later a new structure is allocated in the list, the
function will return that the pointer is valid, although it is actually
not the instance that was originally referred.
.
- Follow-Ups:
- Re: Does malloc() reuse addresses?
- From: Skarmander
- Re: Does malloc() reuse addresses?
- From: avasilev
- Re: Does malloc() reuse addresses?
- From: Dann Corbit
- Re: Does malloc() reuse addresses?
- From: swengineer001@xxxxxxxxx
- Re: Does malloc() reuse addresses?
- From: Barry Schwarz
- Re: Does malloc() reuse addresses?
- From: Ancient_Hacker
- Re: Does malloc() reuse addresses?
- From: goose
- Re: Does malloc() reuse addresses?
- From: Ben Pfaff
- Re: Does malloc() reuse addresses?
- From: Dann Corbit
- Re: Does malloc() reuse addresses?
- Prev by Date: Re: Largest Palindrome
- Next by Date: Re: Reading Binary file
- Previous by thread: calling convention adopted by the gcc compiler for the C programs
- Next by thread: Re: Does malloc() reuse addresses?
- Index(es):
Relevant Pages
|
Loading