1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2024-11-29 11:24:14 +01:00
rpi-vk-driver/driver/LinearAllocator.c

49 lines
721 B
C
Raw Normal View History

2018-08-26 15:11:43 +02:00
#include "LinearAllocator.h"
#include "CustomAssert.h"
#include <stdint.h>
LinearAllocator createLinearAllocator(char* b, unsigned s)
{
assert(b);
assert(s > 0);
LinearAllocator la =
{
.buf = b,
.offset = 0,
.size = s
};
return la;
}
void destroyLinearAllocator(LinearAllocator* la)
{
la->buf = 0;
la->offset = 0;
la->size = 0;
}
void* linearAllocte(LinearAllocator* la, unsigned s)
{
assert(la->buf);
assert(la->size > 0);
if(la->offset + s >= la->size)
{
return 0; //no space left
}
char* p = la->buf + la->offset + s;
la->offset += s;
return p;
}
void linearFree(LinearAllocator* la, void* p)
{
//assert(0); //this shouldn't really happen, just destroy/reset the whole allocator
}