diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2021-10-24 02:15:50 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2021-10-24 02:15:50 +0200 |
| commit | 15e2ff6bb683138878c376a84882b1a6da63cb94 (patch) | |
| tree | 5bac4719b3bf9a5931414a5bed8ead79fda70fe0 /libpsx/src/memory.c | |
| parent | 6989798d87d3e5eded4fbc2e1d19a5b40a4e8051 (diff) | |
| download | psxsdk-15e2ff6bb683138878c376a84882b1a6da63cb94.tar.gz | |
Lazy-initialize heap
Diffstat (limited to 'libpsx/src/memory.c')
| -rw-r--r-- | libpsx/src/memory.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libpsx/src/memory.c b/libpsx/src/memory.c index 9b18556..1d0e6de 100644 --- a/libpsx/src/memory.c +++ b/libpsx/src/memory.c @@ -12,6 +12,7 @@ extern int __bss_start[]; extern int __bss_end[]; static unsigned int first_free_page; +static int init; // 1K granularity and "pages", so more allocations which are small can be done @@ -22,7 +23,7 @@ static unsigned int alloc_size[2048]; // 0x80000000 - 0x8000FFFF RAM used by the BIOS // 0x80010000 - 0x801FFFFF Program memory -void malloc_setup() +static void malloc_setup() { int x; @@ -53,6 +54,14 @@ void malloc_setup() void *malloc(size_t size) { + if (!init) + { + // Setup memory allocation functions + malloc_setup(); + dprintf("Finished setting up memory allocation functions.\n"); + init = 1; + } + dprintf("malloc(%d)\n", size); int x, y; |
