Page 1 of 1

FreeMemory()

Posted: Sat Oct 25, 2008 1:34 pm
by Guimauve
Hello,

When FreeMemory() receive a Null MemoryID we get an compiler ERROR !

I think this function should be capable to handle the Null MemoryID situation internally.

Regards
Guimauve

Posted: Sat Oct 25, 2008 1:37 pm
by Kaeru Gaman
I think the Memory functions are there for performance reasons.
implementing a check would slow them down.

as a programmer you should either know, or check yourself if your pointers are valid.

just my Image

Posted: Sat Oct 25, 2008 1:39 pm
by Mistrel
The program proceeds normally when the debugger is off but does not return a useful result (the result is non-zero).

Granted there are a lot of functions that should fail more gracefully it's completely within our power to check whether the pointer being passed is null or not before it's passed to the function.

Posted: Sat Oct 25, 2008 2:09 pm
by Guimauve
Ok I will create my user procedure like this.

Code: Select all

Procedure FreeMemoryEx(MemoryID)
  
  If MemoryID <> #Null
    FreeMemory(MemoryID)
  EndIf
  
EndProcedure
By the way, the FreeMemory() just tell the system : This memoryID is not used anymore.

Anyway, I let Fred to take care of this request.

Regards
Guimauve

Posted: Sat Oct 25, 2008 3:31 pm
by akj
Alternatively, what about a new IsMemory() command to check whether the memory reference is valid?

This may also be useful for preventing invalid memory crashes.

Posted: Sat Oct 25, 2008 3:42 pm
by ts-soft
akj wrote:Alternatively, what about a new IsMemory() command to check whether the memory reference is valid?

This may also be useful for preventing invalid memory crashes.
If the memory crashes, you use bad code. IsMemory can solve the crash but
not your bad code :wink:
Better is to change the code

yust my two cents

Posted: Sat Oct 25, 2008 4:55 pm
by gnasen
i handle it like this:

Code: Select all

If mem
  FreeMemory(mem)
  mem = 0
EndIf
to check if the memory is still available or freed. (is freed a word :?: )