EXPORT_FUNC TT_Error TT_Free( void** P ) { Int i; Long Size = 0; if ( !P || !*P ) return TT_Err_Ok; #ifdef DEBUG_MEMORY num_free++; i = 0; while ( i < MAX_TRACKED_BLOCKS && pointers[i].base != *P ) i++; if ( i >= MAX_TRACKED_BLOCKS ) fail_free++; else { #ifndef TT_CONFIG_OPTION_THREAD_SAFE TTMemory_Allocated -= pointers[i].size; #endif Size = pointers[i].size; pointers[i].base = NULL; pointers[i].size = 0; } #else i = 0; while ( i < MAX_TRACKED_BIGCHUNKS && pointers[i].base != *P ) i++; /* If we did not found the pointer, then this is a "small" chunk. */ if ( i < MAX_TRACKED_BIGCHUNKS ) { Size = pointers[i].size; pointers[i].base = NULL; pointers[i].base = NULL; } #endif /* DEBUG_MEMORY */ if ( Size > ( UINT_MAX & ~0xFu ) ) huge_free( *P ); else free( *P ); *P = NULL; return TT_Err_Ok; }
void mempool_free(struct Mempool * const p) { if (p->using_mmap) { huge_free(p->space, p->max); } else { free(p->space); } free(p); }
static void compaction_feed_all(struct Compaction *const comp) { for (uint64_t i = 0; i < comp->nr_feed; i++) { const double sec0 = debug_time_sec(); comp->feed_id = i; comp->feed_token = 0; // parallel feed threads conc_fork_reduce(DB_FEED_NR, thread_compaction_feed, comp); db_log_diff(comp->db, sec0, "FEED @%" PRIu64 " [%8" PRIx64 " #%08" PRIx64 "]", comp->start_bit / 3, comp->mts_old[i]->mtid, comp->mts_old[i]->mfh.off / TABLE_ALIGN); } // free feed arenas huge_free(comp->arena, TABLE_ALIGN); }
static int push_vector_grow(struct push_vector * vector, size_t min_alloc) { size_t page_mask = sysconf(_SC_PAGE_SIZE)-1; size_t size = 2*vector->total_size, min_size = vector->size+min_alloc; if (min_size < vector->size) return -1; if (size < min_size) size = min_size; size = (size+page_mask)&(~page_mask); if (size < min_size) return -1; void * new_block = huge_calloc(size, 1); if (new_block == NULL) return -2; memcpy(new_block, vector->block, vector->size); huge_free(vector->block); vector->block = new_block; vector->total_size = size; return 0; }
void block_clear(struct block_matrix * block) { huge_free(block->blocks); free(block->block_offsets); memset(block, 0, sizeof(struct block_matrix)); }