Lazy-initialize heap
This commit is contained in:
parent
6989798d87
commit
15e2ff6bb6
|
@ -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;
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef _PSXSDK_MEMORY_H
|
||||
#define _PSXSDK_MEMORY_H
|
||||
|
||||
void malloc_setup();
|
||||
|
||||
#endif
|
|
@ -1,6 +1,5 @@
|
|||
#include <psx.h>
|
||||
#include <stdio.h>
|
||||
#include "memory.h"
|
||||
|
||||
extern int __bss_start[];
|
||||
extern int __bss_end[];
|
||||
|
@ -38,11 +37,6 @@ void psxsdk_setup()
|
|||
*((unsigned char*)x) = 0;
|
||||
|
||||
dprintf("BSS space cleared.\n");
|
||||
|
||||
// Setup memory allocation functions
|
||||
malloc_setup();
|
||||
|
||||
dprintf("Finished setting up memory allocation functions.\n");
|
||||
|
||||
// Call static constructors
|
||||
call_ctors();
|
||||
|
|
Loading…
Reference in New Issue