-VG_STATIC void vg_linear_clear( void *buffer )
-{
- vg_linear_allocator *alloc = vg_linear_header( buffer );
-
- /* libc mode we recursively free any allocations made */
- if( vg_mem.use_libc_malloc && (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 )
- {
- free( meta->data );
- }
- else
- {
- vg_linear_clear( meta->data );
- vg_linear_allocator *sub = vg_linear_header( meta->data );
-
- free( sub->alloc_table );
- free( sub );
- }
- }
- }
-
- alloc->last_alloc = NULL;
- alloc->last_alloc_size = 0;
- alloc->allocation_count = 0;
- alloc->cur = 0;
-}
-
-/* allocate a FIXED SIZE linear allocator */
-VG_STATIC void *vg_create_linear_allocator( void *lin_alloc, u32 size,
- u16 flags )
-{
- assert( sizeof( vg_linear_allocator ) == 32 );
-
- vg_linear_allocator *header;
- u32 block_size = size + sizeof(vg_linear_allocator);
-
- /* Creating it inside an existing one */
- if( lin_alloc )
- {
- vg_linear_allocator *alloc = vg_linear_header( lin_alloc );
-
- if( alloc->cur + block_size > alloc->size )
- vg_fatal_exit_loop( "Out of memory" );
-
- if( alloc->allocation_count + 1 > VG_MAX_ALLOCATIONS )
- vg_fatal_exit_loop( "Max allocations in linear allocator" );