Oneway malloc¶
A malloc implementation without free for boards where the toolchain does not implement dynamic memory allocation.
The toolchain of MSP-430, for example, does not contain malloc.h::malloc()
and friends. These functions provide the same interface as the stdlib functions, but the option to free memory.
Note
You should prefer statically allocated memory whenever possible.
-
void *
malloc
(msp430_types.h::size_t
size)¶ Allocation a block of memory.
Parameters
size: Size of the block to allocate in bytes. Return values
- The new memory block.
NULL
if the “heap” is exhausted.
- The new memory block.
-
void *
realloc
(void * ptr,msp430_types.h::size_t
size)¶ Allocated a new block of memory and move the existing content.
This function allocates a new block of memory and memcpy()s the content of the ond
ptr
there.Parameters
ptr: Old memory block that was allocated with malloc.h::malloc()
,malloc.h::calloc()
ormalloc.h::realloc()
.size: Size of the new block to allocted in bytes. Return values
- The new memory block.
NULL
if the “heap” is exhausted.
- The new memory block.
-
void *
calloc
(msp430_types.h::size_t
size,msp430_types.h::size_t
cnt)¶ Allocate a memory block and set all its content to zeroes.
Please see
malloc.h::malloc()
for more information.Note
This implementation of
malloc.h::calloc()
does not catch integer overflowsParameters
size: One factor of the number of bytes to allocated. cnt: The other factor of the number of bytes to allocated. Return values
- The new memory block.
NULL
if the “heap” is exhausted.
- The new memory block.
-
void
free
(void * ptr)¶ This is a no-op.
You read correctly: This function does noting.
Note
Keep in mind that this function does not free the memory. It does nothing.
Parameters
ptr: The ignored argument.