|
|
Wiki > Main > AllocatingRAM (compare)
| |||||||||||||||||||||||||||||||||||
Difference: AllocatingRAM (r3 vs. r2)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 layoutThis As an example, this list shows the sections in a compiled
Allocate on the HeapWhen a plugin is loaded, its code and data go in the start of pluginbuf. Codecs work the same way. This is the easiest way, (i.e add a global variable "static char my_buffer[BUFFER_SIZE]" to your file.c) Global variables
static char my_buffer[BUFFER_SIZE]; Cons: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.
Next easiest way. call buffer_alloc() in your "init" method and make sure thats calle before playback starts. char *my_buffer = buffer_alloc(BUFFER_SIZE); Pro: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); Steal a BufferThis 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! Temporarily steal the talk/plugin/audio buffer, each has its own size and cons...
Plugin Buffer ( plugin_get_buffer() )size_t size_available; void *my_buffer = rb->plugin_get_audio_buffer(&size_available);
dynamic allocation like "malloc()" (bufalloc())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.
r4 - 28 May 2011 - 01:30:28 - SeanBartell
Revision r3 - 29 Mar 2011 - 03:45 - SeanBartellRevision r2 - 28 Mar 2011 - 23:39 - SeanBartell Copyright © by the contributing authors.
|