AMX Memory Manager
K
A
DAK
131
10.5 Memory Assignment
The sections of memory which make up the memory pool controlled by the Memory
Manager must be provided by your application. The Memory Manager makes no
assumptions concerning the whereabouts of the memory over which it has control.
Sections of memory are assigned to the Memory Manager by your application. You must
provide a Memory Assignment Procedure which will be called by the Memory Manager
to acquire the memory sections over which it is to have control. A definition of this
procedure is provided in Chapter 10.6.
If no Memory Assignment Procedure is provided, the Memory Manager will always
report that no memory is available whenever any task requests a memory block.
When your AMX system is first started, the Memory Manager has no memory to allocate
to tasks. When AMX is started, the Memory Manager determines if you have provided a
Memory Assignment Procedure. If one was provided, the Memory Manager calls it to
acquire a memory section. Your procedure must return a pointer to a memory section
and indicate its size. The manner in which your procedure derives section pointers is up
to you.
The Memory Manager initializes the section returned by your Memory Assignment
Procedure. If the size of a section is less than the minimum required by the Memory
Manager, the section is ignored. Your Memory Assignment Procedure is then called
again. This process proceeds until your procedure returns an indication that no more
sections are available.
Once your Memory Assignment Procedure indicates that there are no more sections
available, the Memory Manager ceases its calls to your procedure. At that point, the
Memory Manager has reached the upper limit of the memory over which it has control.
The Memory Manager will subsequently attempt to allocate a memory block for any
calling task from the memory sections which it has acquired. If the first memory section
has no free blocks large enough to meet the needs of the calling task, the next memory
section is checked to see if it meets the requirements of the caller. This process is
repeated until a block can be allocated to the caller or until all initialized sections have
been exhausted.
Subsequent requests to the Memory Manager for a memory block will fail if a memory
block of adequate size cannot be found in any of these initialized memory sections.