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

3 Memory Slabs
6 A :dfn:`memory slab` is a kernel object that allows memory blocks
7 to be dynamically allocated from a designated memory region.
8 All memory blocks in a memory slab have a single fixed size,
9 allowing them to be allocated and released efficiently
10 and avoiding memory fragmentation concerns.
19 Any number of memory slabs can be defined (limited only by available RAM). Each
20 memory slab is referenced by its memory address.
22 A memory slab has the following key properties:
30 * A **buffer** that provides the memory for the memory slab's blocks.
33 The memory slab's buffer must be aligned to an N-byte boundary, where
34 N is a power of 2 larger than 2 (i.e. 4, 8, 16, ...). To ensure that
35 all memory blocks in the buffer are similarly aligned to this boundary,
38 A memory slab must be initialized before it can be used. This marks all of
41 A thread that needs to use a memory block simply allocates it from a memory
42 slab. When the thread finishes with a memory block,
43 it must release the block back to the memory slab so the block can be reused.
46 for one to become available.
47 Any number of threads may wait on an empty memory slab simultaneously;
48 when a memory block becomes available, it is given to the highest-priority
51 Unlike a heap, more than one memory slab can be defined, if needed. This
52 allows for a memory slab with smaller blocks and others with larger-sized
53 blocks. Alternatively, a memory pool object may be used.
58 A memory slab's buffer is an array of fixed-size blocks,
61 The memory slab keeps track of unallocated blocks using a linked list;
67 Defining a Memory Slab
70 A memory slab is defined using a variable of type :c:type:`k_mem_slab`.
73 The following code defines and initializes a memory slab that has 6 blocks
74 that are 400 bytes long, each of which is aligned to a 4-byte boundary.
76 .. code-block:: c
83 Alternatively, a memory slab can be defined and initialized at compile time
87 that the macro defines both the memory slab and its buffer.
89 .. code-block:: c
93 Similarly, you can define a memory slab in private scope:
95 .. code-block:: c
99 Allocating a Memory Block
102 A memory block is allocated by calling :c:func:`k_mem_slab_alloc`.
104 The following code builds on the example above, and waits up to 100 milliseconds
105 for a memory block to become available, then fills it with zeroes.
108 .. code-block:: c
116 printf("Memory allocation time-out");
119 Releasing a Memory Block
122 A memory block is released by calling :c:func:`k_mem_slab_free`.
124 The following code builds on the example above, and allocates a memory block,
127 .. code-block:: c
132 ... /* use memory block pointed at by block_ptr */
138 Use a memory slab to allocate and free memory in fixed-size blocks.
140 Use memory slab blocks when sending large amounts of data from one thread
141 to another, to avoid unnecessary copying of the data.