@@ -95,6 +95,43 @@ unbounded list searches, at the expense of some fragmentation
95
95
resistance. This :c:kconfig: `CONFIG_SYS_HEAP_ALLOC_LOOPS ` value may be
96
96
chosen by the user at build time, and defaults to a value of 3.
97
97
98
+ Multi-Heap Wrapper Utility
99
+ **************************
100
+
101
+ The ``sys_heap `` utility requires that all managed memory be in a
102
+ single contiguous block. It is common for complicated microcontroller
103
+ applications to have more complicated memory setups that they still
104
+ want to manage dynamically as a "heap". For example, the memory might
105
+ exist as separate discontiguous regions, different areas may have
106
+ different cache, performance or power behavior, peripheral devices may
107
+ only be able to perform DMA to certain regions, etc...
108
+
109
+ For those situations, Zephyr provides a ``sys_multi_heap `` utility.
110
+ Effectively this is a simple wrapper around a set of one or more
111
+ ``sys_heap `` objects. It should be initialized after its child heaps
112
+ via :c:func: `sys_multi_heap_init `, after which each heap can be added
113
+ to the managed set via :c:func: `sys_multi_heap_add_heap `. No
114
+ destruction utility is provided; just as for ``sys_heap ``,
115
+ applications that want to destroy a multi heap should simply ensure
116
+ all allocated blocks are freed (or at least will never be used again)
117
+ and repurpose the underlying memory for another usage.
118
+
119
+ It has a single pair of allocation entry points,
120
+ :c:func: `sys_multi_heap_alloc ` and
121
+ :c:func: `sys_multi_heap_aligned_alloc `. These behave identically to
122
+ the ``sys_heap `` functions with similar names, except that they also
123
+ accept an opaque "configuration" parameter. This pointer is
124
+ uninspected by the multi heap code itself; instead it is passed to a
125
+ callback function provided at initialization time. This
126
+ application-provided callback is responsible for doing the underlying
127
+ allocation from one of the managed heaps, and may use the
128
+ configuration parameter in any way it likes to make that decision.
129
+
130
+ When unused, a multi heap may be freed via
131
+ :c:func: `sys_multi_heap_free `. The application does not need to pass
132
+ a configuration parameter. Memory allocated from any of the managed
133
+ ``sys_heap `` objects may be freed with in the same way.
134
+
98
135
System Heap
99
136
***********
100
137
0 commit comments