EZmalloc

Ever tried to dynamically allocate menory (for excample on an AVR)? It is possible, malloc has been ported to AVR, but you have to use custom linkerscripts and such.

I implemented a version of malloc which does the job of malloc with only a normal array of data.

The library does not implement any security-features or cleanup. The application must make sure to free the memory and must not write beyond boundaries.

The library can be used on any microcontroller architecture, when a C-compiler is availabele.

Functions:

  • void init_memory(void); – Initializes Memory
  • void * malloc(uint16_t size); – Just as malloc, but size is uint16_t. Size is in bytes (uint8_t).
  • uint8_t delete(void * ptr); – instead of free(), to keep name conventions.
  • void * calloc(void * ptr, uint16_t newsize); Just as calloc; size param like malloc

Defines (ezmalloc.h):

  • #define memory_size     156 – Memory size for malloc to work in (here 156 byte). Unit is bytes (uint8_t). The lib will reserve (1,25 * memory_size) +1 Bytes of memory.

Downloads:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.