1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-15 10:13:34 +00:00
lovr/src/core/arr.c
bjorn eb1e257209 Add new array implementation; Upgrade filesystem;
Filesystem:

- Uses streaming file IO.
- Uses less memory when requiring files.
- Simplifies its require path implementation.
2019-06-16 13:30:30 -07:00

23 lines
561 B
C

#include "arr.h"
#include "util.h"
#include <stdlib.h>
#include <string.h>
void _arr_reserve(void** data, void* temp, size_t n, size_t* capacity, size_t stride) {
size_t oldCapacity = *capacity;
while (*capacity < n) {
*capacity <<= 1;
lovrAssert(*capacity > 0, "Out of memory");
}
if (*data == temp) {
*data = realloc(NULL, *capacity * stride);
lovrAssert(*data, "Out of memory");
memcpy(*data, temp, oldCapacity * stride);
} else {
*data = realloc(*data, *capacity * stride);
lovrAssert(*data, "Out of memory");
}
}