Skip to content
Snippets Groups Projects
Commit d6b56ff6 authored by Wesley W. Terpstra's avatar Wesley W. Terpstra
Browse files

We can't allocate more than 64k worth of entries, because 64k-1 is EB_NULL.

parent 2f48036d
No related merge requests found
......@@ -36,11 +36,14 @@
#include "memory.h"
union eb_memory_item* eb_memory_array = 0;
static EB_POINTER(eb_memory_item) eb_memory_array_size = 128; /* ie: initally 256 */
static uint32_t eb_memory_array_size = 128; /* ie: initally 256 */
int eb_expand_array(void) {
void* new_address;
EB_POINTER(eb_memory_item) next_size, i;
uint32_t next_size, i;
/* When next_size reaches the maximum of 64k entries, fail */
if (eb_memory_array_size == 65536) return -1;
/* Doubling ensures constant cost */
next_size = eb_memory_array_size + eb_memory_array_size;
......@@ -58,7 +61,7 @@ int eb_expand_array(void) {
/* Link together the expanded free list */
for (i = eb_memory_array_size; i != next_size; ++i)
eb_memory_array[i].free_item.next = i+1;
eb_memory_array[next_size-1].free_item.next = EB_END_OF_FREE;
eb_memory_free = eb_memory_array_size;
eb_memory_array_size = next_size;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment