void _memory_shutdown( void ) { memory_set_tracker( _memory_no_tracker ); _atomic_allocate_shutdown(); _memory_system.shutdown(); }
void* memory_reallocate( void* p, uint64_t size, unsigned int align ) { FOUNDATION_ASSERT_MSG( ( p < _memory_temporary.storage ) || ( p >= _memory_temporary.end ), "Trying to reallocate temporary memory" ); _memory_untrack( p ); p = _memsys.reallocate( p, size, align ); _memory_track( p, size ); return p; }
void _memory_shutdown( void ) { memory_tracker_t no_tracker = {0}; memory_set_tracker( no_tracker ); _atomic_allocate_shutdown(); _memsys.shutdown(); }
void* memory_allocate( uint64_t size, unsigned int align, memory_hint_t hint ) { void* p; if( ( hint == MEMORY_TEMPORARY ) && _memory_temporary.storage && ( size + align < _memory_temporary.maxchunk ) ) { align = _memory_get_align( align ); p = _memory_align_pointer( _atomic_allocate_linear( size + align ), align ); } else { p = _memsys.allocate( memory_context(), size, align, hint ); } _memory_track( p, size ); return p; }
void* memory_allocate(hash_t context, size_t size, unsigned int align, unsigned int hint) { void* p = 0; if (_memory_temporary.storage && (hint & MEMORY_TEMPORARY)) { unsigned int tmpalign = _memory_get_align_forced(align); if (size + tmpalign < _memory_temporary.maxchunk) { p = _memory_align_pointer(_atomic_allocate_linear(size + tmpalign), tmpalign); FOUNDATION_ASSERT(!((uintptr_t)p & 1)); if (hint & MEMORY_ZERO_INITIALIZED) memset(p, 0, (size_t)size); } } if (!p) p = _memory_system.allocate(context ? context : memory_context(), size, align, hint); _memory_track(p, size); return p; }
void* memory_allocate( uint64_t context, uint64_t size, unsigned int align, int hint ) { void* p; if( ( hint & MEMORY_TEMPORARY ) && _memory_temporary.storage && ( size + align < _memory_temporary.maxchunk ) ) { align = _memory_get_align( align ); if( align < FOUNDATION_SIZE_POINTER ) align = FOUNDATION_SIZE_POINTER; p = _memory_align_pointer( _atomic_allocate_linear( size + align ), align ); FOUNDATION_ASSERT( !( (uintptr_t)p & 1 ) ); memset( p, 0, (size_t)size ); } else { p = _memory_system.allocate( context ? context : memory_context(), size, align, hint ); } _memory_track( p, size ); return p; }
void memory_deallocate( void* p ) { if( ( p < _memory_temporary.storage ) || ( p >=_memory_temporary.end ) ) _memsys.deallocate( p ); _memory_untrack( p ); }
void* memory_allocate_zero_context( uint16_t context, uint64_t size, unsigned int align, memory_hint_t hint ) { void* p = _memsys.allocate_zero( context, size, align, hint ); _memory_track( p, size ); return p; }
int _memory_initialize( const memory_system_t memory ) { _memsys = memory; return _memsys.initialize(); }
void _memory_finalize(void) { memory_set_tracker(_memory_no_tracker); _atomic_allocate_finalize(); _memory_system.finalize(); }
int _memory_initialize(const memory_system_t memory) { _memory_system = memory; memset(&_memory_stats, 0, sizeof(_memory_stats)); return _memory_system.initialize(); }