Lines Matching +full:memory +full:- +full:to +full:- +full:memory

3 Memory Heaps
6 Zephyr provides a collection of utilities that allow threads to
7 dynamically allocate memory.
15 The simplest way to define a heap is statically, with the
17 with a given name that manages a memory region of the
20 Heaps can also be created to manage arbitrary regions of
21 application-controlled memory using :c:func:`k_heap_init`.
23 Allocating Memory
26 Memory can be allocated from a heap using :c:func:`k_heap_alloc`,
28 desired. This functions similarly to standard C ``malloc()``,
31 The heap supports blocking operation, allowing threads to go to sleep
32 until memory is available. The final argument is a
37 Releasing Memory
40 Memory allocated with :c:func:`k_heap_alloc` must be released using
41 :c:func:`k_heap_free`. Similar to standard C ``free()``, the pointer
44 ``NULL`` value is defined to have no effect.
53 applications that want to manage their own blocks of memory in
55 or more complicated. Unlike ``k_heap``, all calls to any ``sys_heap``
62 Internally, the ``sys_heap`` memory block is partitioned into "chunks"
66 length of the next lower ("left") chunk in physical memory, a bit
67 indicating whether the chunk is in use, and chunk-indexed link
68 pointers to the previous and next chunk in a "free list" to which
71 The heap code takes reasonable care to avoid fragmentation. Free
73 blocks within one power of two (i.e. a bucket for blocks of 3-4
74 chunks, another for 5-8, 9-16, etc...) this allows new allocations to
75 be made from the smallest/most-fragmented blocks available. Also, as
76 allocations are freed and added to the heap, they are automatically
77 combined with adjacent free blocks to prevent fragmentation.
80 heap memory, including the variable-length list of bucket list heads
81 (which depend on heap size). The only external memory required is the
85 any users to prevent concurrent access. Only one context may be
88 The heap code takes care to present high performance and reliable
89 latency. All ``sys_heap`` API functions are guaranteed to complete
91 complete within 1-200 cycles. One complexity is that the search of
93 "might fit") has a compile-time upper bound of iterations to prevent
96 chosen by the user at build time, and defaults to a value of 3.
98 Multi-Heap Wrapper Utility
101 The ``sys_heap`` utility requires that all managed memory be in a
103 applications to have more complicated memory setups that they still
104 want to manage dynamically as a "heap". For example, the memory might
107 only be able to perform DMA to certain regions, etc...
113 to the managed set via :c:func:`sys_multi_heap_add_heap`. No
115 applications that want to destroy a multi heap should simply ensure
117 and repurpose the underlying memory for another usage.
121 :c:func:`sys_multi_heap_aligned_alloc`. These behave identically to
124 uninspected by the multi heap code itself; instead it is passed to a
126 application-provided callback is responsible for doing the underlying
128 configuration parameter in any way it likes to make that decision.
138 :c:func:`sys_multi_heap_free`. The application does not need to pass
139 a configuration parameter. Memory allocated from any of the managed
145 The :dfn:`system heap` is a predefined memory allocator that allows
146 threads to dynamically allocate memory from a common memory region in
147 a :c:func:`malloc`-like manner.
149 Only a single system heap is defined. Unlike other heaps or memory
151 memory address.
153 The size of the system heap is configurable to arbitrary sizes,
154 subject to space availability.
156 A thread can dynamically allocate a chunk of heap memory by calling
158 guaranteed to be aligned on a multiple of pointer sizes. If a suitable
159 chunk of heap memory cannot be found ``NULL`` is returned.
161 When the thread is finished with a chunk of heap memory it can release
162 the chunk back to the system heap by calling :c:func:`k_free`.
164 Defining the Heap Memory Pool
167 The size of the heap memory pool is specified using the
170 By default, the heap memory pool size is zero bytes. This value instructs
171 the kernel not to define the heap memory pool object. The maximum size is limited
172 by the amount of available memory in the system. The project build will fail in
179 If the application tries to set a value that's less than the minimum value, this
182 To force a smaller than minimum value to be used, the application may enable the
187 Allocating Memory
190 A chunk of heap memory is allocated by calling :c:func:`k_malloc`.
192 The following code allocates a 200 byte chunk of heap memory, then fills it
195 .. code-block:: c
204 printf("Memory not allocated");
207 Releasing Memory
210 A chunk of heap memory is released by calling :c:func:`k_free`.
212 The following code allocates a 75 byte chunk of memory, then releases it
215 .. code-block:: c
220 ... /* use memory block */
226 Use the heap memory pool to dynamically allocate memory in a
227 :c:func:`malloc`-like manner.