mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-03-22 01:44:36 -05:00
I found another way to optimize the rom space by implementing a custom malloc, free, realloc and calloc function. This reduces rom size by 3 KB and IWRAM usage by 1 KB. (elimination of __malloc_av). The original implementation is much more complex and larger than it needs to be. The custom malloc is implemented as a bitmap allocator. It keeps a bitmap to track which pages of the heap are allocated. Like the original allocator, it uses the free space in EWRAM after the multiboot gba rom. But unlike the original allocator, we control the size with CUSTOM_MALLOC_POOL_SIZE. The custom malloc can be disabled with USE_CUSTOM_MALLOC.
22 lines
486 B
C
22 lines
486 B
C
#ifndef CUSTOM_MALLOC_H
|
|
#define CUSTOM_MALLOC_H
|
|
|
|
#include "debug_mode.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
/// malloc.c defines a custom bitmap allocator implementation that replaces newlibs'
|
|
/// if the USE_CUSTOM_MALLOC flag is set. That makes sure the linker won't pull in all the malloc related code
|
|
/// in newlibc (alongside the 1KB IWRAM __malloc_av variable)
|
|
|
|
void malloc_init_default_pool(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |