summaryrefslogtreecommitdiff
path: root/libs/raylib/src/rmem.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/raylib/src/rmem.h')
-rw-r--r--libs/raylib/src/rmem.h33
1 files changed, 17 insertions, 16 deletions
diff --git a/libs/raylib/src/rmem.h b/libs/raylib/src/rmem.h
index 9c7d0a7..8f92003 100644
--- a/libs/raylib/src/rmem.h
+++ b/libs/raylib/src/rmem.h
@@ -161,9 +161,7 @@ RMEMAPI intptr_t BiStackMargins(BiStack destack);
#if defined(RMEM_IMPLEMENTATION)
-#include <stdio.h> // Required for:
-#include <stdlib.h> // Required for:
-#include <string.h> // Required for:
+#include <stdio.h> // Required for: malloc(), calloc(), free()
//----------------------------------------------------------------------------------
// Defines and Macros
@@ -205,7 +203,7 @@ MemPool CreateMemPool(const size_t size)
mempool.stack.size = size;
mempool.stack.mem = malloc(mempool.stack.size*sizeof *mempool.stack.mem);
- if (mempool.stack.mem==NULL)
+ if (mempool.stack.mem == NULL)
{
mempool.stack.size = 0UL;
return mempool;
@@ -252,7 +250,9 @@ void *MemPoolAlloc(MemPool *const mempool, const size_t size)
const size_t BUCKET_INDEX = (ALLOC_SIZE >> MEMPOOL_BUCKET_BITS) - 1;
// If the size is small enough, let's check if our buckets has a fitting memory block.
- if (BUCKET_INDEX < MEMPOOL_BUCKET_SIZE && mempool->buckets[BUCKET_INDEX] != NULL && mempool->buckets[BUCKET_INDEX]->size >= ALLOC_SIZE)
+ if ((BUCKET_INDEX < MEMPOOL_BUCKET_SIZE) &&
+ (mempool->buckets[BUCKET_INDEX] != NULL) &&
+ (mempool->buckets[BUCKET_INDEX]->size >= ALLOC_SIZE))
{
new_mem = mempool->buckets[BUCKET_INDEX];
mempool->buckets[BUCKET_INDEX] = mempool->buckets[BUCKET_INDEX]->next;
@@ -424,9 +424,9 @@ size_t GetMemPoolFreeMemory(const MemPool mempool)
{
size_t total_remaining = (uintptr_t)mempool.stack.base - (uintptr_t)mempool.stack.mem;
- for (MemNode *n=mempool.freeList.head; n != NULL; n = n->next) total_remaining += n->size;
+ for (MemNode *n = mempool.freeList.head; n != NULL; n = n->next) total_remaining += n->size;
- for (size_t i=0; i<MEMPOOL_BUCKET_SIZE; i++) for (MemNode *n = mempool.buckets[i]; n != NULL; n = n->next) total_remaining += n->size;
+ for (int i = 0; i < MEMPOOL_BUCKET_SIZE; i++) for (MemNode *n = mempool.buckets[i]; n != NULL; n = n->next) total_remaining += n->size;
return total_remaining;
}
@@ -436,7 +436,7 @@ void MemPoolReset(MemPool *const mempool)
if (mempool == NULL) return;
mempool->freeList.head = mempool->freeList.tail = NULL;
mempool->freeList.len = 0;
- for (size_t i = 0; i < MEMPOOL_BUCKET_SIZE; i++) mempool->buckets[i] = NULL;
+ for (int i = 0; i < MEMPOOL_BUCKET_SIZE; i++) mempool->buckets[i] = NULL;
mempool->stack.base = mempool->stack.mem + mempool->stack.size;
}
@@ -453,7 +453,7 @@ bool MemPoolDefrag(MemPool *const mempool)
}
else
{
- for (size_t i=0; i<MEMPOOL_BUCKET_SIZE; i++)
+ for (int i = 0; i < MEMPOOL_BUCKET_SIZE; i++)
{
while (mempool->buckets[i] != NULL)
{
@@ -593,7 +593,7 @@ ObjPool CreateObjPool(const size_t objsize, const size_t len)
}
else
{
- for (size_t i=0; i<objpool.freeBlocks; i++)
+ for (int i = 0; i < objpool.freeBlocks; i++)
{
union ObjInfo block = { .byte = &objpool.stack.mem[i*objpool.objSize] };
*block.index = i + 1;
@@ -617,7 +617,7 @@ ObjPool CreateObjPoolFromBuffer(void *const buf, const size_t objsize, const siz
objpool.stack.size = objpool.freeBlocks = len;
objpool.stack.mem = buf;
- for (size_t i=0; i<objpool.freeBlocks; i++)
+ for (int i = 0; i < objpool.freeBlocks; i++)
{
union ObjInfo block = { .byte = &objpool.stack.mem[i*objpool.objSize] };
*block.index = i + 1;
@@ -655,6 +655,7 @@ void *ObjPoolAlloc(ObjPool *const objpool)
// Head = &pool[*Head * pool.objsize];
objpool->stack.base = (objpool->freeBlocks != 0UL)? objpool->stack.mem + (*ret.index*objpool->objSize) : NULL;
memset(ret.byte, 0, objpool->objSize);
+
return ret.byte;
}
else return NULL;
@@ -694,7 +695,7 @@ BiStack CreateBiStack(const size_t len)
{
BiStack destack = { 0 };
if (len == 0UL) return destack;
-
+
destack.size = len;
destack.mem = malloc(len*sizeof *destack.mem);
if (destack.mem==NULL) destack.size = 0UL;
@@ -726,11 +727,11 @@ void DestroyBiStack(BiStack *const destack)
void *BiStackAllocFront(BiStack *const destack, const size_t len)
{
if ((destack == NULL) || (destack->mem == NULL)) return NULL;
-
+
const size_t ALIGNED_LEN = __AlignSize(len, sizeof(uintptr_t));
// front end stack is too high!
if (destack->front + ALIGNED_LEN >= destack->back) return NULL;
-
+
uint8_t *ptr = destack->front;
destack->front += ALIGNED_LEN;
return ptr;
@@ -739,11 +740,11 @@ void *BiStackAllocFront(BiStack *const destack, const size_t len)
void *BiStackAllocBack(BiStack *const destack, const size_t len)
{
if ((destack == NULL) || (destack->mem == NULL)) return NULL;
-
+
const size_t ALIGNED_LEN = __AlignSize(len, sizeof(uintptr_t));
// back end stack is too low
if (destack->back - ALIGNED_LEN <= destack->front) return NULL;
-
+
destack->back -= ALIGNED_LEN;
return destack->back;
}