Re: Does malloc() reuse addresses?
- From: "swengineer001@xxxxxxxxx" <swengineer001@xxxxxxxxx>
- Date: 14 Jul 2006 12:40:36 -0700
avasilev wrote:
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.
If you are doing what you say with the instance array, why are you not
removing the pointer from the array when you free the element of the
list. Sounds like you might want to rethink your design a little.
.
- References:
- Does malloc() reuse addresses?
- From: avasilev
- Does malloc() reuse addresses?
- Prev by Date: Re: Does malloc() reuse addresses?
- Next by Date: Re: Does malloc() reuse addresses?
- Previous by thread: Re: Does malloc() reuse addresses?
- Next by thread: Re: Does malloc() reuse addresses?
- Index(es):
Relevant Pages
|
Loading