Page 1 of 3

4.1 with betas: FreeMemory()

Posted: Sun Nov 12, 2006 12:21 pm
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:

Posted: Sun Nov 12, 2006 2:10 pm
by ABBKlaus
confirmed :wink:

Image

Posted: Sun Nov 12, 2006 4:05 pm
by Deeem2031
This feature was removed "long" time ago, only the help is wrong.

Re: 4.1 with betas: FreeMemory()

Posted: Sun Nov 12, 2006 5:04 pm
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...

Re: 4.1 with betas: FreeMemory()

Posted: Sun Nov 12, 2006 5:16 pm
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!

Posted: Sun Nov 12, 2006 5:28 pm
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?

Posted: Sun Nov 12, 2006 5:44 pm
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 :)

Posted: Sun Nov 12, 2006 5:53 pm
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.

Posted: Sun Nov 12, 2006 6:07 pm
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

Posted: Sun Nov 12, 2006 6:34 pm
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

Posted: Sun Nov 12, 2006 6:41 pm
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

Posted: Sun Nov 12, 2006 6:43 pm
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:

Posted: Sun Nov 12, 2006 6:44 pm
by T-Light
Sorry netmaestro, that last comment was on my routines, not yours, I'll give it a go now :)

Re: 4.1 with betas: FreeMemory()

Posted: Sun Nov 12, 2006 7:00 pm
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.

Posted: Sun Nov 12, 2006 7:07 pm
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 :)