F
frakie
Hi 'body,
is there a method to check if a pointer is pointing a freed memory
location?
is there a method to check if a pointer is pointing a freed memory
location?
frakie said:Hi 'body,
is there a method to check if a pointer is pointing a freed memory
location?
Non by using Standard facilities. You could, and should, keep track of this
information yourself. How exactly you do so is up to you and the projects
requirements.
One simple method is to set to NULL any pointer that has not been
initialised to point to valid storage, or such storage has been free'ed.
frakie said:D'oh!
Thank you..
Hi 'body,
is there a method to check if a pointer is pointing a freed memory
location?
banu said:I think the question is whether its is possible to test if a
pointer(initialized explicitly or has a random garbage)is pointing to
freed memory i.e memory which is not part of the current process in
execution.
Although I don't know the std library function or code for this, but
work around would be to find out the absolute memory address space for
the program in execution. This would involve finding address range
for code segment (cs), data segment (ds) and stack. Once u have the
address range, u can test the address value stored in pointer against
the address range and take decision accordingly.
Maybe I am not fully correct with the solution, but It seems right to
me at least logically.
I think the question is whether its is possible to test if a
pointer(initialized explicitly or has a random garbage)is pointing to
freed memory
Yes.
i.e memory which is not part of the current process in
execution.
Although I don't know the std library function or code for this,
but
work around would be to find out the absolute memory address space for
the program in execution.
This would involve finding address range
for code segment (cs), data segment (ds) and stack.
Once u have the
address range, u can test the address value stored in pointer against
the address range and take decision accordingly.
Maybe I am not fully correct with the solution, but It seems right to
me at least logically.
[big snip]Flash Gordon said:banu wrote, On 03/10/07 20:06:
Yes.
frakie said:is there a method to check if a pointer is pointing a freed memory
location?
Keith said:[big snip]Flash Gordon said:banu wrote, On 03/10/07 20:06:
Yes.
Are you saying "Yes, that's the question", or are you saying
that the answer to the question is Yes?
I don't think there's any portable way to determine whether a
pointer points to freed memory. There may not even be a
non-portable way. Are you suggesting there is?
[big snip]Flash Gordon said:banu wrote, On 03/10/07 20:06:
Yes.
Are you saying "Yes, that's the question", or are you saying
that the answer to the question is Yes?
I don't think there's any portable way to determine whether a pointer
points to freed memory. There may not even be a non-portable way.
Are you suggesting there is?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.