d0b72e2590
The buflib memory allocator is handle based and can free and compact, move or resize memory on demand. This allows to effeciently allocate memory dynamically without an MMU, by avoiding fragmentation through memory compaction. This patch adds the buflib library to the core, along with convinience wrappers to omit the context parameter. Compaction is not yet enabled, but will be in a later patch. Therefore, this acts as a replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug menu. See buflib.h for some API documentation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657
36 lines
1.1 KiB
C
36 lines
1.1 KiB
C
|
|
#ifndef __CORE_ALLOC_H__
|
|
#define __CORE_ALLOC_H__
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include "buflib.h"
|
|
|
|
/* All functions below are wrappers for functions in buflib.h, except
|
|
* they have a predefined context
|
|
*/
|
|
void core_allocator_init(void);
|
|
int core_alloc(const char* name, size_t size);
|
|
int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks *ops);
|
|
int core_alloc_maximum(const char* name, size_t *size, struct buflib_callbacks *ops);
|
|
bool core_shrink(int handle, void* new_start, size_t new_size);
|
|
int core_free(int handle);
|
|
size_t core_available(void);
|
|
|
|
/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call
|
|
* the move callbacks and are therefore unsafe in the core */
|
|
|
|
#ifdef BUFLIB_DEBUG_BLOCKS
|
|
void core_print_allocs(void (*print)(const char*));
|
|
void core_print_blocks(void (*print)(const char*));
|
|
#endif
|
|
#ifdef BUFLIB_DEBUG_BLOCK_SINGLE
|
|
int core_get_num_blocks(void);
|
|
void core_print_block_at(int block_num, char* buf, size_t bufsize);
|
|
#endif
|
|
|
|
static inline void* core_get_data(int handle)
|
|
{
|
|
extern struct buflib_context core_ctx;
|
|
return buflib_get_data(&core_ctx, handle);
|
|
}
|
|
#endif /* __CORE_ALLOC_H__ */
|