static JKGMemBlock_t *JKG_Mem_AddBlock(int size) { int idx; // Add new entry in the MemBlocks dynamic array idx = JKG_Arrays_AddArrayElement((void **)&MemBlocks, sizeof(JKGMemBlock_t), &BlockCount); // Since these allocs are static, we'll use trap_TrueMalloc for it // This will make the alloc in the engine's zone memory // Allocs are fitted with a marker, so we can quickly determine if an alloc is made by this (in G_Free) trap_TrueMalloc(&MemBlocks[idx].ptr, size+4); MemBlocks[idx].size = size; if (!MemBlocks[idx].ptr) { G_Error("G_Alloc: Failed to allocate %i bytes of memory\n", size); } memset(MemBlocks[idx].ptr,0,size); *(int *)MemBlocks[idx].ptr = ALLOCMARKER; #ifndef __linux__ (int)MemBlocks[idx].ptr += 4; #else { // linux doesnt like += 4 on pointers >.> int tmp = (int)MemBlocks[idx].ptr; tmp += 4; MemBlocks[idx].ptr = (void *)tmp; } #endif return &MemBlocks[idx]; }
unsigned int JKG_Pairs_Add(KeyPairSet_t *set, const char *key, const char *value){ unsigned int index = JKG_Arrays_AddArrayElement((void **)&set->pairs, sizeof(KeyPair_t), &set->count); G_NewString2((void **)&set->pairs[index].key, key); G_NewString2((void **)&set->pairs[index].value, value); return index; }