memory array allocator
More...
memory array allocator
pseudo dynamic allocation in static memory arrays
- Author
- Tobias Heider heide.nosp@m.rt@n.nosp@m.m.ifi.nosp@m..lmu.nosp@m..de
-
Koen Zandberg koen@.nosp@m.berg.nosp@m.zand..nosp@m.net
◆ memarray_element_t
Memory pool element.
Internal memarray element struct to increase code readability
◆ memarray_alloc()
Allocate memory chunk in memarray pool.
- Precondition
mem != NULL
- Note
- Allocated structure is not cleared before returned
- Parameters
-
[in,out] | mem | memarray pool to allocate block in |
- Returns
- pointer to allocated structure, if enough memory was available
-
NULL, on failure
Definition at line 78 of file memarray.h.
◆ memarray_available()
Returns the number of blocks available.
- Parameters
-
- Returns
- Number of elements available in the memarray pool
◆ memarray_calloc()
Allocate and clear memory chunk in memarray pool.
- Precondition
mem != NULL
- Parameters
-
[in,out] | mem | memarray pool to allocate block in |
- Returns
- pointer to allocated structure, if enough memory was available
-
NULL, on failure
Definition at line 99 of file memarray.h.
◆ memarray_extend()
void memarray_extend |
( |
memarray_t * |
mem, |
|
|
void * |
data, |
|
|
size_t |
num |
|
) |
| |
Extend the memarray with a new memory region.
This function extends the memarray pool with a new memory region. The region must be able to fit the supplied number of elements of the size used when initializing this memarray.
- Precondition
mem != NULL
-
data != NULL
-
num != 0
- Parameters
-
[in,out] | mem | memarray pool to extend |
[in] | data | pointer to user-allocated data |
[in] | num | number of elements in data |
◆ memarray_free()
static void memarray_free |
( |
memarray_t * |
mem, |
|
|
void * |
ptr |
|
) |
| |
|
inlinestatic |
Free memory chunk in memarray pool.
- Precondition
mem != NULL
-
ptr != NULL
- Parameters
-
[in,out] | mem | memarray pool to free block in |
[in] | ptr | pointer to memarray chunk |
Definition at line 117 of file memarray.h.
◆ memarray_init()
void memarray_init |
( |
memarray_t * |
mem, |
|
|
void * |
data, |
|
|
size_t |
size, |
|
|
size_t |
num |
|
) |
| |
Initialize memarray pool with free list.
- Precondition
mem != NULL
-
data != NULL
-
size >= sizeof(void*)
-
num != 0
- Parameters
-
[in,out] | mem | memarray pool to initialize |
[in] | data | pointer to user-allocated data |
[in] | size | size of a single element in data |
[in] | num | number of elements in data |
◆ memarray_reduce()
int memarray_reduce |
( |
memarray_t * |
mem, |
|
|
void * |
data, |
|
|
size_t |
num |
|
) |
| |
Reduce the memarray space, subtracting the memory pool.
It is up to the user to free all chunks in the reduced pool. The function will check if all elements in the pool are freed.
- Parameters
-
[in,out] | mem | memarray pool to reduce |
[in] | data | pointer to the user-allocated data to reduce |
[in] | num | number of elements to reduce the data pool with |