Oneway malloc

A malloc implementation without free for boards where the toolchain does not implement dynamic memory allocation. More...

Detailed Description

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() 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.
See also
Two-Level Segregated Fit memory allocator

Files

file  malloc.h
 

Functions

void * malloc (size_t size)
 Allocation a block of memory. More...
 
void * realloc (void *ptr, size_t size)
 Allocated a new block of memory and move the existing content. More...
 
void * calloc (size_t size, size_t cnt)
 Allocate a memory block and set all its content to zeroes. More...
 
void free (void *ptr)
 This is a no-op. More...
 

Function Documentation

◆ calloc()

void* calloc ( size_t  size,
size_t  cnt 
)

Allocate a memory block and set all its content to zeroes.

Please see malloc() for more information.

Note
This implementation of calloc() does not catch integer overflows
Parameters
[in]sizeOne factor of the number of bytes to allocated.
[in]cntThe other factor of the number of bytes to allocated.
Returns
The new memory block. NULL if the "heap" is exhausted.

◆ free()

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
[in]ptrThe ignored argument.

◆ malloc()

void* malloc ( size_t  size)

Allocation a block of memory.

Parameters
[in]sizeSize of the block to allocate in bytes.
Returns
The new memory block. NULL if the "heap" is exhausted.

◆ realloc()

void* realloc ( void *  ptr,
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 one ptr there.

         We do not know the size of the old block, so illegal reads would be likely,
         if it was not for the fact that the memory heap up.
Parameters
[in]ptrOld memory block that was allocated with malloc(), calloc() or realloc().
[in]sizeSize of the new block to allocated in bytes.
Returns
The new memory block. NULL if the "heap" is exhausted.