Re: Memory Allocation under GS/OS [message #69 is a reply to message #66] |
Sat, 11 October 2014 07:42 |
Oz
Messages: 21 Registered: October 2014 Location: France
|
Member |
|
|
Before asking the Memory Manager to allocate us memory space, there is an easy way to know if we can get the expected amount of memory. Because we allocate memory by block of 64 KB (one full Bank), the only thing we care is how many banks the GS/OS can allocate us.
The code is, as usually, very simple :
PushLong #0 ; Ask Memory Manager for Free Space size
_FreeMem
PLA
PLA
*--
CMP #$0007 ; We need 7 Bank of 64 KB
BCC ErrorMemory ; not enough memory, so exit
The FreeMem returns the free space size in Bytes, as a 32 bits integer value. We ignore the low WORD and focus on the high one. We have there the number of 64 KB areas available.
We have anyway to check each AllocOneBank calls because of the memory fragmentation (we ask for full banks, not areas that could be located over a bank boundary).
Olivier
[Updated on: Sat, 11 October 2014 07:44] Report message to a moderator
|
|
|