Apple2.gs Forums
Discussions for Apple IIgs Programming and other fun stuff. // Infinitum!

Home » Apple IIgs Programming » Video Game Programming » Memory Allocation under GS/OS
Re: Memory Allocation under GS/OS [message #69 is a reply to message #66] Sat, 11 October 2014 07:42 Go to previous message
Oz is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Loading Files from Disk in Assembly Language using GS/OS
Next Topic: Unpack a Picture using the PackBytes compression format
Goto Forum:
  


Current Time: Wed Feb 05 19:42:51 MST 2025

Total time taken to generate the page: 0.01096 seconds