
CHAPTER 6 MEMORY MANAGEMENT
User’s Manual U14833EJ2V0UM
75
6.6
Variable-Length Memory Pools
Like fixed-length memory pools, these are memory pools from which memory blocks can be repeatedly acquired
and returned by a task or handler processing program via a service call. Unlike a fixed-length memory pool, however,
the size of the memory blocks that can be acquired can be specified when an acquisition request is sent.
6.6.1
Creating variable-length memory pools
A variable-length memory pool is created by issuing the service call (a)cre_mpl. When acre_mpl is issued, the ID
number of the memory pool can be assigned by the kernel. Also, specifying the static API CRE_MPL allows
processing equivalent to cre_mpl to be carried out at kernel initialization.
When (a)cre_mpl is issued, the kernel secures an area of the specified size from the user pool and makes it the
memory pool main body. If this area is successfully secured, data such as the attribute and the address of the
memory pool main body area is stored in the variable-length memory control block corresponding to the specified ID
number, and the control block is initialized.
6.6.2
Deleting variable-length memory pools
A variable-length memory pool is deleted by issuing the service call del_mpl. When del_mpl is issued, the kernel
returns the area of the memory pool main body to the user pool and then invalidates the control block. At this time, if
there is a task waiting to acquire a memory block from the variable-length memory pool to be deleted, all tasks are
released from the waiting state. For tasks released from waiting, the error code E_DLT is returned indicating that the
memory pool was deleted.
Note that even if there are parts of memory blocks in the target variable-length memory pool that have not been
returned, the variable-length memory pool will still be deleted. Care is required at this time because the task or
handler that had acquired that memory block is not informed of the deletion of the memory pool.
6.6.3
Variable-length memory blocks
A variable-length memory pool is made up of memory blocks without fixed sizes. Also, to maintain a state in which
the largest possible blocks can be acquired, processing is performed to join together memory blocks to form
connected areas upon return. A header for block management (16 bytes) is therefore included in the memory block,
making the size of the area actually removed from memory pool when a memory block is acquired larger than the
specified size. Note that the specified memory block size must be an integral multiple of 8. If a value that is not an
integral multiple of 8 is specified when a memory block is acquired, the kernel will automatically round the size to an
integral multiple of 8.
The structure of a variable-length memory block is shown below.
Figure 6-3. Variable-Length Memory Block
Memory block
Address passed as
memory block address
Requested
acquisition size
Header
16 bytes