Wiki > Main > AllocatingRAM (compare)
Difference: AllocatingRAM (r4 vs. r3)
Rockbox has a "No Malloc" policy you can read about at WhyNoMalloc but sometimes you really do need to grab some buffer possibly temporarily. This page will explain the different methods available.
As an example, this list shows the sections in a compiled
When a plugin is loaded, its code and data go in the start of pluginbuf. Codecs work the same way.
Note that this covers getting memory in the first place. In some cases, a full malloc() is unavoidable; you must get a large buffer with one of these methods and use TLSF to allocate within the large buffer.
By far the easiest method:
static char 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.
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.
size_t size_available; // In codec: void *my_buffer = ci->codec_get_buffer(&size_available); // In plugin: void *my_buffer = rb->plugin_get_buffer(&size_available);
This is used by codecs/plugins to get the rest of the codec/plugin buffer. This space is reserved for the codec/plugin anyway, so you may as well use it!
size_t size_available; void *my_buffer = rb->plugin_get_audio_buffer(&size_available);
If a plugin stops playback, it can use the sound buffer.
Most frowned-on method of allocation, use this carefully... The buffer is allocated as a handle in the playback buffer and could be moving around the buffer as playback advances. BuflibMemoryManagement is a project to allocate memory more dynamically. The project is just beginning as of May 2011.
r4 - 28 May 2011 - 01:30:28 - SeanBartellRevision r4 - 28 May 2011 - 01:30 - SeanBartell
Revision r3 - 29 Mar 2011 - 03:45 - SeanBartell
Copyright © by the contributing authors.