Beispiel #1
0
static void JKG_Mem_RemoveBlock(void* ptr) {
	unsigned int i, idx = -1;
	if (*(int *)((int)ptr-4) != ALLOCMARKER) {
		// Alloc aint ours for sure
		return;
	}
	for(i = 0; i<BlockCount; i++){
		if(ptr == MemBlocks[i].ptr){
			idx = i;
			break;
		}
	}
	if(idx == -1)
		return; // Not one of our blocks, dont try to free

	// Free the block and remove the entry from the array
	#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
	trap_TrueFree(&MemBlocks[idx].ptr);
	JKG_Arrays_RemoveArrayElement((void **)&MemBlocks, idx, sizeof(JKGMemBlock_t), &BlockCount);
}
void JKG_Pairs_Remove(KeyPairSet_t *set, int index){
	// Just free, if its NULL it'll bail out anyway, no need to check twice
	G_Free(set->pairs[index].key);
	G_Free(set->pairs[index].value);
	JKG_Arrays_RemoveArrayElement((void **)&set->pairs, index, sizeof(KeyPair_t), &set->count);
}