Skip to content

Commit 2d65d72

Browse files
Nicolas Pitrenashif
authored andcommitted
lib/os/heap: add alignment precisions to the documentation
sys_heap_alloc() returns memory aligned to sizeof(void *). sys_heap_aligned_alloc() may accept 0 for align which defaults to sizeof(void *). Semantically we can consider 0 as "don't care". Signed-off-by: Nicolas Pitre <[email protected]>
1 parent 47de5a0 commit 2d65d72

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

include/sys/sys_heap.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ void sys_heap_init(struct sys_heap *h, void *mem, size_t bytes);
7676
* Returns a pointer to a block of unused memory in the heap. This
7777
* memory will not otherwise be used until it is freed with
7878
* sys_heap_free(). If no memory can be allocated, NULL will be
79-
* returned.
79+
* returned. The allocated memory is guaranteed to have a starting
80+
* address which is a multiple of sizeof(void *). If a bigger alignment
81+
* is necessary then sys_heap_aligned_alloc() should be used instead.
8082
*
8183
* @note The sys_heap implementation is not internally synchronized.
8284
* No two sys_heap functions should operate on the same heap at the
@@ -93,8 +95,8 @@ void *sys_heap_alloc(struct sys_heap *h, size_t bytes);
9395
* Behaves in all ways like sys_heap_alloc(), except that the returned
9496
* memory (if available) will have a starting address in memory which
9597
* is a multiple of the specified power-of-two alignment value in
96-
* bytes. The resulting memory can be returned to the heap using
97-
* sys_heap_free().
98+
* bytes. With align=0 this behaves exactly like sys_heap_alloc().
99+
* The resulting memory can be returned to the heap using sys_heap_free().
98100
*
99101
* @param h Heap from which to allocate
100102
* @param align Alignment in bytes, must be a power of two

0 commit comments

Comments
 (0)