|
||||||||||||||||||||||||||||||||||||
Different ways to allocate RAM usage for your featureRockbox 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.Compile-time RAM layoutAs an example, this list shows the sections in a compiledrockbox.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.
Allocation methodsNote 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.Global variablesBy 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.
Allocate from soundbufchar *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.
Use the rest of the codec/plugin buffersize_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!
Steal the sound buffersize_t size_available; void *my_buffer = rb->plugin_get_audio_buffer(&size_available);If a plugin stops playback, it can use the sound buffer.
Use buflibBuflibMemoryManagement is a project to allocate memory more dynamically. The project is just beginning as of May 2011.
r5 - 02 Apr 2021 - 20:46:06 - UnknownUser
Copyright © by the contributing authors.
|