The red-black tree heap provides a memory allocator using a red-black tree to maintain blocks of memory.
More...
The red-black tree heap provides a memory allocator using a red-black tree to maintain blocks of memory.
The red-black tree heap provides a memory allocator suitable to implement the malloc() and free() interface. It uses a first-fit allocation strategy. In the red-black tree heap the administration data structures are not contained in the managed memory area. Thus writing beyond the boundaries of a chunk does not damage the data to maintain the heap. This can be used for example in a task stack allocator which protects the task stacks from access by other tasks. The allocated and free memory parts of the managed area are called chunks. Each chunk needs a descriptor which is stored outside of the managed area.
◆ rtems_rbheap_extend_descriptors
Handler to extend the available chunk descriptors.
This handler is called when no more chunk descriptors are available. An example implementation is this:
{
rtems_rbheap_add_to_spare_descriptor_chain(
control, chunk);
}
}
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
Definition: intercom.c:87
Red-black heap chunk descriptor.
Definition: rbheap.h:70
Red-black heap control.
Definition: rbheap.h:126
- See also
- rtems_rbheap_extend_descriptors_never() and rtems_rbheap_extend_descriptors_with_malloc().
◆ rtems_rbheap_allocate()
Allocates a chunk of memory of at least size bytes from the red-black tree heap control.
The chunk begin is aligned by the value specified in rtems_rbheap_initialize().
- Parameters
-
[in,out] | control | The red-black tree heap. |
[in] | size | The requested chunk size in bytes. |
- Return values
-
NULL | Not enough free space in the heap. |
otherwise | Pointer to allocated chunk of memory. |
◆ rtems_rbheap_free()
Frees a chunk of memory ptr allocated from the red-black tree heap control.
- Parameters
-
[in,out] | control | The red-black tree heap. |
[in] | ptr | The pointer to the chunk of memory. |
- Return values
-
RTEMS_SUCCESSFUL | Successful operation. |
RTEMS_INVALID_ID | The chunk of memory is not a valid chunk in the red-black tree heap. |
RTEMS_INCORRECT_STATE | The chunk of memory is not in the right state. |
◆ rtems_rbheap_initialize()
Initializes the red-black tree heap control.
- Parameters
-
[in,out] | control | The red-black tree heap. |
[in] | area_begin | The managed memory area begin. |
[in] | area_size | The managed memory area size. |
[in] | alignment | The minimum chunk alignment. |
[in] | extend_descriptors | The handler to extend the available chunk descriptors. |
[in] | handler_arg | The handler argument. |
- Return values
-
RTEMS_SUCCESSFUL | Successful operation. |
RTEMS_INVALID_ADDRESS | The memory area is invalid. |
RTEMS_NO_MEMORY | Not enough chunk descriptors. |