- vg_mem.rtmemory = vg_create_linear_allocator( NULL, size, VG_MEMORY_SYSTEM );
- vg_mem.scratch = vg_create_linear_allocator( vg_mem.rtmemory,
- size_scratch,
- VG_MEMORY_SYSTEM );
+ vg_mem.rtmemory = _vg_create_linear_allocator( NULL, size, VG_MEMORY_SYSTEM,
+ "VG Root" );
+ vg_mem.scratch = _vg_create_linear_allocator( vg_mem.rtmemory,
+ size_scratch,
+ VG_MEMORY_SYSTEM,
+ "Scratch buffer" );
+}
+
+VG_STATIC void vg_mem_log( void *lin_alloc, int depth, const char *name )
+{
+ if( vg_mem.use_libc_malloc ){
+ vg_linear_allocator *alloc = vg_linear_header( lin_alloc );
+
+ u32 s = alloc->size;
+ f32 p = ((float)alloc->cur / (float)alloc->size) * 100.0f;
+
+ for( int i=0; i<depth; i++ ) printf( " " );
+ printf( "LA(%s): %u bytes, %f%% used\n", name, s, p );
+
+ if( alloc->flags & VG_MEMORY_SYSTEM ){
+ for( u32 i=0; i<alloc->allocation_count; i++ ){
+ vg_allocation_meta *meta = &alloc->alloc_table[i];
+
+ if( meta->type == k_allocation_type_block ){
+ for( int i=0; i<depth+1; i++ ) printf( " " );
+ printf( "B(%s): %u bytes\n", meta->name, meta->size );
+ }
+ else{
+ vg_mem_log( meta->data, depth +1, meta->name );
+ }
+ }
+ }
+ else{
+ for( int i=0; i<depth+1; i++ ) printf( " " );
+ printf( "<opaque memory> (UNTRACKED)\n" );
+ }
+ }
+ else{
+ vg_error( "allocations are not tracked (turn on libc mode)\n" );
+ }