FreeMemory() should zero the pointer
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
FreeMemory() should zero the pointer
After *buffer = AllocateMemory(1024), *buffer contains a pointer to the address of the memory block. After FreeMemory(*buffer), the value of the pointer is of no conceivable use anymore. Imho it would be cleaner and more intuitive if after FreeMemory(*buffer), the programmer could test *buffer and find it's 0 now.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
Re: FreeMemory() should zero the pointer
Since *buffer belongs to you, there's nothing that keeps you from setting *buffer to zero yourself, directly after you did a FreeMemory(*buffer). In fact, that's what I implemented with a debugging macro.netmaestro wrote:After *buffer = AllocateMemory(1024), *buffer contains a pointer to the address of the memory block. After FreeMemory(*buffer), the value of the pointer is of no conceivable use anymore. Imho it would be cleaner and more intuitive if after FreeMemory(*buffer), the programmer could test *buffer and find it's 0 now.
I use this zeroed pointer for debugging checks only, since in normal code, there is no need to dereference this pointer. As you pointed out "the value of the pointer is of no conceivalble use anymore".
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: FreeMemory() should zero the pointer
That is simply impossible.Imho it would be cleaner and more intuitive if after FreeMemory(*buffer), the programmer could test *buffer and find it's 0 now.
The function gets a copy of the 4 Byte Long Value "*Buffer" and not the original. So it can't change it (Only if it would be a macro but u can write that yourself).
Apart from that Mrs Lincoln, how was the show?
-
- Enthusiast
- Posts: 767
- Joined: Sat Jan 24, 2004 6:56 pm
Re: FreeMemory() should zero the pointer
@Konne
i find it odd that it can't be zero out after FreeMemory, but if you say so, i really don't know, but thanks for the explanation anyway
** Edit **
Well i ment if you can do
Why can't the compiler ?
but if it can't be done, because of some technically "things" or something
, then no big deal anyway, just would be nice
Best Regads Henrik
Okay..Konne wrote: Not it isn't (the only Value).
It's used to Simpolize a Pointer isn't valid.
Well okay then, i don't know what go's on behind the scene.That is simply impossible.
The function gets a copy of the 4 Byte Long Value "*Buffer" and not the original. So it can't change it (Only if it would be a macro but u can write that yourself).
i find it odd that it can't be zero out after FreeMemory, but if you say so, i really don't know, but thanks for the explanation anyway

** Edit **
Well i ment if you can do
Code: Select all
FreeMemory(*FileBuffer1a)
*FileBuffer1a=0
but if it can't be done, because of some technically "things" or something

Best Regads Henrik
Last edited by Henrik on Sun Nov 12, 2006 7:11 pm, edited 1 time in total.