4.1 with betas: FreeMemory()

Everything else that doesn't fall into one of the other PB categories.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

4.1 with betas: FreeMemory()

Post by Psychophanta »

Syntax

FreeMemory(*MemoryID)
Description

Free the memory previously allocated with AllocateMemory() or ReAllocateMemory(). If the specified *MemoryID is -1 then all the previously allocated memory areas are freed.

Code: Select all

*a.b=AllocateMemory(512)
FreeMemory(-1)
That's funny!

BTW moderators, i hope this bug is fixed instead you erase bug posts as sometimes you do! :evil:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

confirmed :wink:

Image
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

This feature was removed "long" time ago, only the help is wrong.
irc://irc.freenode.org/#purebasic
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: 4.1 with betas: FreeMemory()

Post by freak »

Psychophanta wrote:BTW moderators, i hope this bug is fixed instead you erase bug posts as sometimes you do! :evil:
Hey, thanks for the insult. I can't stand you either. Have a nice day...
quidquid Latine dictum sit altum videtur
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: 4.1 with betas: FreeMemory()

Post by Psychophanta »

freak wrote:
Psychophanta wrote:BTW moderators, i hope this bug is fixed instead you erase bug posts as sometimes you do! :evil:
Hey, thanks for the insult.
Heey! Timo, where is the insult??
freak wrote:I can't stand you either. Have a nice day...
Well, you or someone deleted one post in which i explained several possible bugs, and now i don't remember what were they :o :(
A nice day, a nice day, grrr.

Thanks anyway!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
T-Light
User
User
Posts: 45
Joined: Sat Aug 05, 2006 5:42 pm
Location: UK

Post by T-Light »

Which 'feature' has been removed, freememory or freememory(-1)?

Just going through some old thread code and I'm getting
'The memory pointer passed to freememory() is invalid' error

I'm just using freememory with a valid pointer (not -1), anyway round this?
T-Light
User
User
Posts: 45
Joined: Sat Aug 05, 2006 5:42 pm
Location: UK

Post by T-Light »

To be more accurate, my line looks like this...

If *FileBuffer1a : FreeMemory(*FileBuffer1a) : EndIf

I thought this was saying if *Filebuffer1a exists then free it? It seems to work most of the time then fails with 'The memory pointer passed to freememory() is invalid'

Is there another way of doing this? I can take freememory out of the loop but the memory usage goes through the roof.

Any advice would be very much appreciated :)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

FreeMemory(*buffer) doesn't zero out the pointer. So until you do *buffer=0, If *buffer... is always true whether it's a valid memory block anymore or not. If you do:

Code: Select all

Freememory(*buffer) : *buffer = 0
your current approach will work much better.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi
Why not

Code: Select all

*FileBuffer1a = AllocateMemory(1024)
  
  Debug MemorySize(*FileBuffer1a)
  
  If MemorySize(*FileBuffer1a) 
    FreeMemory(*FileBuffer1a)
  EndIf
  
   Debug MemorySize(*FileBuffer1a)
Best Henrik
T-Light
User
User
Posts: 45
Joined: Sat Aug 05, 2006 5:42 pm
Location: UK

Post by T-Light »

Thankyou very much for the suggestions guys but I'm having problems with both of them :?

Netmaestro -
Freememory(*buffer) : *buffer = 0

It sets the pointer to 0 after the failed freememory call

Henrik -
If MemorySize(*FileBuffer1a) : FreeMemory(*FileBuffer1a) :EndIf

Rather than crashing on the freememory call, it crashes on the memorysize call.

This maybe bad coding practice but would I be looking at serious problems if I just checked if the memory pointer was more than 0 and if so set the pointer to 0? Is there something internally that keeps count, or would this be OK?

Here's a line, haven't tested it yet :shock:
if *filebuffer1a>0 : *filebuffer1a=0 : endif
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

T-Light, try this out, it should be bulletproof:

Code: Select all

Macro FreeMemoryEx(buffer)
  If buffer
    FreeMemory(buffer) : buffer=0
  EndIf
EndMacro


*pt = AllocateMemory(1024)

FreeMemoryEx(*pt) ; First call actually frees the memory
FreeMemoryEx(*pt) ; subsequent calls don't try to free
FreeMemoryEx(*pt) ; the memory because the first successful
FreeMemoryEx(*pt) ; call reset *pt to 0
T-Light
User
User
Posts: 45
Joined: Sat Aug 05, 2006 5:42 pm
Location: UK

Post by T-Light »

OK, no crashes, but it works as if I'd just commented out the freememory routines, memory usage goes through the roof, was worth a try :cry:
T-Light
User
User
Posts: 45
Joined: Sat Aug 05, 2006 5:42 pm
Location: UK

Post by T-Light »

Sorry netmaestro, that last comment was on my routines, not yours, I'll give it a go now :)
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 4.1 with betas: FreeMemory()

Post by Fred »

Psychophanta wrote:
Syntax

FreeMemory(*MemoryID)
Description

Free the memory previously allocated with AllocateMemory() or ReAllocateMemory(). If the specified *MemoryID is -1 then all the previously allocated memory areas are freed.

Code: Select all

*a.b=AllocateMemory(512)
FreeMemory(-1)
That's funny!

BTW moderators, i hope this bug is fixed instead you erase bug posts as sometimes you do! :evil:
The -1 feature is no more supported, the help is wrong, right.

On a side note, I'm the only one authorized to remove bugs entries hereand they are only deleted if:
1) it's fixed.
2) it's not reproducable after asking a few times.
3) it's not a PB bug but an OS limitation (they are moved in general discussion or coding questions).

What would be the point to delete silently some random bug reports ? If the count was that important, i would clean it completely every weeks.
T-Light
User
User
Posts: 45
Joined: Sat Aug 05, 2006 5:42 pm
Location: UK

Post by T-Light »

Tried you new routine netmaestro and still got the same error...
The memory pointer passed to freememory() is invalid.

In the main code using the buffers I'm reallocating memory to increase the size of the buffers, don't see how this would affect it, but it's the only part of the routines that aren't straightforward.
eg fill buffer a
buffer a full?
reallocate more memory for bufferb and copy buffera into it
fill bufferb
bufferb full?
reallocate more memory for buffera and copy bufferb into it
and so on...

Think I'll go in and simplify everything to see if I can get away with fixed sized buffers and do away with swapping and reallocation.

Thanks again :)
Locked