Ioto Memory Allocator

Ioto provides a wrapper over the standard malloc memory allocator. This wrapper performs global memory allocation checking and is tailored to the needs of embedded applications.

Memory Allocation

It is difficult and error-prone for programmers to check the result of every API call that can possibly fail due to memory allocation errors. Calls such as strdup and asprintf are often assumed to succeed, but they can, and do fail when memory is depleted.

A better approach is to proactively detect and handle memory allocation errors in one place. The Ioto allocator handles memory allocation errors globally. When Ioto detects a memory allocation failure, it invokes the global memory exception handler. This configurable handler can then decide what is the best course of recovery. The default action is to restart the application (rather than just crash).

Wrapper Routines

The safe runtime provides three memory allocation routines that wrap the standard libc routines.

The ralloc routine allocates memory and checks for memory failures and invokes the global exception handler if the memory allocation fails.

The rfree routine frees memory and is NULL tolerant (see below). This routine accepts memory allocated via ralloc or malloc.

Theh ralloct routine is a convenience function to allocate memory for a typed object. For example:

mem = ralloct(struct shape);

NULL Tolerance

Ioto adopts a technique call NULL tolerance where APIs, wherever possible, tolerate NULL arguments and attempt to do something reasonable with their arguments, rather than crashing the applications.

The standard C library is not NULL tolerant. If you pass a NULL pointer to routines such as as free() or strlen() your program will crash.

The Ioto memory allocator is NULL tolerant when calling rfree.

© Embedthis Software. All rights reserved.