2013-11-17 21:36:18 +00:00
|
|
|
#include "Memory.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <cassert>
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void *Memory::naiveArrayInsert(void **array, unsigned long item_size, int item_count, int location) {
|
|
|
|
char **barray = (char **)array;
|
2013-11-17 21:36:18 +00:00
|
|
|
|
|
|
|
assert(location >= 0);
|
|
|
|
assert(location <= item_count);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
*barray = (char *)realloc(*barray, item_size * (item_count + 1));
|
|
|
|
if (location < item_count) {
|
|
|
|
memmove(*barray + item_size * (location + 1), *barray + item_size * location,
|
|
|
|
item_size * (item_count - location));
|
2013-11-17 21:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *barray + item_size * location;
|
|
|
|
}
|