FreeMemory()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

FreeMemory()

Post 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
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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
oh... and have a nice day.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post 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.
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Post 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
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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.
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Post 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 :?: )
Post Reply