Compile-time RAM layout

As an example, this list shows the sections in a compiled rockbox.elf, indicating how RAM is allocated at compile-time. The section arrangement varies somewhat between platforms and is determined by the linker script (firmware/target/arm/as3525/app.lds in this case, for the Sansa e200v2). The interesting parts for memory allocation are audiobuf, codecbuf, and pluginbuf.

When a plugin is loaded, its code and data go in the start of pluginbuf. Codecs work the same way.

Global variables

By far the easiest method:

staticchar my_buffer[BUFFER_SIZE];

This can be used anywhere. In a codec or plugin, space will be reserved in codecbuf or pluginbuf until the codec/plugin is unloaded. Otherwise, space will be reserved permanently in .data, .rodata, or .bss.

Easy, fast, no overhead.

Can't be freed or resized.

Size must be known at compile-time.

Allocate from soundbuf

char *my_buffer = buffer_alloc(BUFFER_SIZE);

This takes some space from the front of soundbuf. It can't be used by plugins or codecs, since it can't be freed. This method is useful when the size required is known at boot-time.