|
5 | 5 | #include <sys/lcd.h> |
6 | 6 | #include <debug.h> |
7 | 7 |
|
8 | | -// This allocator uses the 2nd part of the VRAM as the heap. It gives you 76K of memory, |
| 8 | +// This allocator uses the 2nd part of the VRAM as another area for heap allocations, providing 76KB more memory, |
9 | 9 | // but requires you to only use the first part of the VRAM for the LCD configured in 8bpp. |
10 | 10 |
|
11 | | -#define MALLOC_MINSIZE 6 // minimal size (avoid blocks that are too small) |
| 11 | +// When passed to malloc, returns how much free memory there's left |
| 12 | +#define MAGIC_SIZE_QUERY_FREEMEM 0xFFFFFF |
| 13 | + |
| 14 | +// minimal size (avoid blocks that are too small) |
| 15 | +#define MALLOC_MINSIZE 6 |
12 | 16 |
|
13 | 17 | static unsigned int freeslotpos(unsigned int n) |
14 | 18 | { |
@@ -101,7 +105,8 @@ void* _vram2_malloc(const size_t alloc_size) |
101 | 105 | if (alloc_size == 0) |
102 | 106 | return NULL; |
103 | 107 |
|
104 | | - if (alloc_size == 0xFFFFFF) |
| 108 | + // This allows callers to query how much free memory there is left |
| 109 | + if (alloc_size == MAGIC_SIZE_QUERY_FREEMEM) |
105 | 110 | return (void*)((heap_ptrend - heap_ptr) + (heap2_ptrend - heap2_ptr)); |
106 | 111 |
|
107 | 112 | if (alloc_size <= sizeof(char6_t)) |
@@ -330,8 +335,8 @@ void* _vram2_realloc(void* ptr, const size_t size) |
330 | 335 | } |
331 | 336 |
|
332 | 337 | if ((((size_t)ptr >= (size_t)&tab2[0]) && ((size_t)ptr < (size_t)&tab2[ALLOC2])) || |
333 | | - (((size_t)ptr >= (size_t)&tab3[0]) && ((size_t)ptr < (size_t)&tab3[ALLOC2])) || |
334 | | - (((size_t)ptr >= (size_t)&tab6[0]) && ((size_t)ptr < (size_t)&tab6[ALLOC2]))) |
| 338 | + (((size_t)ptr >= (size_t)&tab3[0]) && ((size_t)ptr < (size_t)&tab3[ALLOC3])) || |
| 339 | + (((size_t)ptr >= (size_t)&tab6[0]) && ((size_t)ptr < (size_t)&tab6[ALLOC6]))) |
335 | 340 | { |
336 | 341 | // ok |
337 | 342 | } |
|
0 commit comments