This chapter describes details of the functions provided by μT-Kernel/SM (System Manager).
Overall Note and Supplement | |
---|---|
|
The system memory management functions manage all the memory (system memory) allocated dynamically by μT-Kernel. This includes memory used internally by μT-Kernel as well as task stacks, message buffers, and memory pools.
System memory management functions include memory allocation libraries that manage memory through subdividing system memory into smaller blocks.
The system memory management functions are for use not only within μT-Kernel but also used by applications, subsystems, and device drivers.
Memory allocation library provides functions equivalent to malloc
/calloc
/realloc
/free
provided by C standard library.
These memories are all allocated as memory with a protection level specified in TSVCLimit
.
None.
Only when all the service profile items below are set to be effective, this API can be used.
Allocates the memory of bytes specified in size
and returns the start address of the allocated memory in addr
.
When the specified size of memory cannot be allocated or 0 is specified in size
, NULL is returned in addr
.
APIs in the memory allocation library, including Kmalloc, cannot be called from a task-independent portion and while dispatch or interrupt is disabled. Such a call may lead to an undefined behavior including possible system failure, and the caller is responsible for guaranteeing the state on the call.
Any value can be specified in size
. Note that a larger memory size than the number of bytes specified in size
may be allocated internally due to allocating the management space, aligning the allocated memory address, or other reasons. For example, when the implementation specifies that the least allocatable memory size is 16 bytes and the alignment is an 8-byte unit, 16-byte memory is allocated internally even if a value less than 16 bytes is specified in size
. Similarly, 24-byte memory is allocated even if 20 bytes is specified in size
.
None.
Only when all the service profile items below are set to be effective, this API can be used.
Allocates the specified number (nmemb
) of contiguous memory blocks of the specified bytes (size
), clears them with 0, then returns the start address of them in addr
. This memory allocation operation is identical to allocating one memory block of the number of size
* nmemb
bytes.
When the specified number of memory blocks cannot be allocated or 0 is specified in nmemb
or size
, NULL is returned in addr
.
APIs in the memory allocation libraries, including Kcalloc, cannot be called from a task-independent portion and while dispatch or interrupt is disabled. Such a call may lead to an undefined behavior including possible system failure, and the caller is responsible for guaranteeing the state on the call.
A larger memory size than the number of size
* nmemb
bytes may be allocated internally. For more details, see the additional note for Kmalloc.
None.
Only when all the service profile items below are set to be effective, this API can be used.
Changes the size of the previously allocated memory specified in ptr
to the size specified in size
. At that time, reallocates the memory and returns the start address of the reallocated memory in addr
.
Generally, addr
results in different value from ptr
because the memory start address is moved by reallocating the memory with resizing. The content of the reallocated memory is retained. To do so, the memory content is copied during the Krealloc processing. The memory that becomes free by reallocation will be released.
The start address of the memory allocated previously by Kmalloc, Kcalloc, or Krealloc must be specified in ptr
. The caller must guarantee the validity of ptr
.
If NULL is specified in ptr
, only the new memory allocation is performed. This operation is identical to Kmalloc.
When the specified size of memory cannot be reallocated or 0 is specified in size
, NULL is returned in addr
. In this case, the memory specified by ptr
is only released if a value other than NULL is specified in ptr
. This operation is identical to Kfree.
APIs in the memory allocation library, including Krealloc, cannot be called from a task-independent portion and while dispatch or interrupt is disabled. Such a call may lead to an undefined behavior including possible system failure, and the caller is responsible for guaranteeing the state on the call.
The memory address returned in addr
may be the same as ptr
in some cases, for example, when the memory size becomes smaller than before by reallocation or when the reallocation is performed without moving the memory start address because an unallocated memory area was around the memory specified in ptr
.
A larger memory size than the number of bytes specified in size
may be allocated internally. For more details, see the additional note for Kmalloc.
None.
None.
Only when all the service profile items below are set to be effective, this API can be used.
Releases the memory specified in ptr
.
The start address of the memory allocated previously by Kmalloc, Kcalloc, or Krealloc must be specified in ptr
. The caller must guarantee the validity of ptr
.
APIs in the memory allocation library, including Kfree, cannot be called from a task-independent portion and while dispatch or interrupt is disabled. Such a call may lead to an undefined behavior including possible system failure, and the caller is responsible for guaranteeing the state on the call.