@cas
Tested with debugger on
The problem with freeing memory doesn't happen on 32 bit windows (XP home with SP3)
So either 64 bit windows behaves different, or there's a bug in the 64 bit version of PB
@trond
Try to write something into the allocated memory and it will allocate the memory in RAM, it's just a trick that is also used on Linux,
the OS just reserves as many memory as it need to hold the first page of every memory block,
but it you write something into it, it starts to allocate new RAM pages.
You can see that when you use this prog:
Code: Select all
#MemSize = 1024*1024
CompilerIf Defined(ByteVector, #PB_Structure) = 0
Structure ByteVector
b.b[0]
EndStructure
CompilerEndIf
Define *memPtr.ByteVector
For n = 1 To 1024
*memPtr = AllocateMemory(#MemSize)
If Not *memPtr
CallDebugger
EndIf
For idx = 0 To 4000
*memPtr\b[idx] = -1
Next idx
Next n
CallDebugger
If you increase the end value of the idx loop to about 4095,
it will allocate the next page, so RAM usage goes up.
It isn't exactly 4096 (one page) when it happens, because of the internal
overhead for managing the memory block.
So it can happen that you have several programs running all together using more RAM than is available, but when all start to write something to the allocated memory, the OS says, pardon, no more memory.