AMX Memory Manager
K
A
DAK
129
Use Count
When the Memory Manager allocates a block of memory for the use of a task, it sets the
block's use count to one. The block owner may call the Memory Manager procedure
ajmau to increase the use count. If the use count is increased by one, the block will have
to be released twice before it becomes free.
The block use count provides the key to memory block ownership. The Memory
Manager owns all free blocks in its memory pool. One or more tasks can own an already
allocated memory block. This concept of block ownership is the same as that of buffer
ownership provided by the AMX Buffer Manager. Refer to Chapters 9.3 and 9.4 for
examples of the proper use of this ownership concept.
Size
The Memory Manager procedure ajmgsz can be used to obtain the size of a particular
memory block. This feature can be useful if one task is given ownership of a memory
block by another task. The new block owner can check the size of the memory block to
be sure that it meets its requirements. If a task corrupts the contents of any memory
location outside the bounds of the memory block, the effects are unpredictable and
potentially disastrous.
Once allocated, a memory block cannot grow or shrink in size. Hence, the size of a
memory block cannot be dynamically adjusted by its owner.