Skip to content

Commit 6c87ff9

Browse files
committed
Clarify some things, fix copy/paste typos.
1 parent 4fae833 commit 6c87ff9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/libc/allocator_VRAM2.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
#include <sys/lcd.h>
66
#include <debug.h>
77

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,
99
// but requires you to only use the first part of the VRAM for the LCD configured in 8bpp.
1010

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
1216

1317
static unsigned int freeslotpos(unsigned int n)
1418
{
@@ -101,7 +105,8 @@ void* _vram2_malloc(const size_t alloc_size)
101105
if (alloc_size == 0)
102106
return NULL;
103107

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)
105110
return (void*)((heap_ptrend - heap_ptr) + (heap2_ptrend - heap2_ptr));
106111

107112
if (alloc_size <= sizeof(char6_t))
@@ -330,8 +335,8 @@ void* _vram2_realloc(void* ptr, const size_t size)
330335
}
331336

332337
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])))
335340
{
336341
// ok
337342
}

0 commit comments

Comments
 (0)