struct
{
void *rtmemory,
- *scratch,
- *async;
+ *scratch;
int use_libc_malloc;
u32 quota;
struct vg_linear_allocator
{
u32 size;
- /* */
- /* */
- /* */
u32 cur;
- /* */
- /* */
- /* */
u16 allocation_count;
- /* */
u16 flags;
- /* */
u32 last_alloc_size;
- /* */
- /* */
- /* */
void *last_alloc;
- /* */
- /* */
- /* */
- /* */
- /* */
- /* */
- /* */
vg_allocation_meta *alloc_table;
- /* */
- /* */
- /* */
- /* */
- /* */
- /* */
- /* */
#ifdef _WIN32
/* 32 bit pointers! */
};
#pragma pack(pop)
-VG_STATIC void vg_fatal_exit_loop( const char *error );
+VG_STATIC void vg_fatal_error( const char *fmt, ... );
VG_STATIC void vg_error(const char *fmt, ...);
VG_STATIC void vg_info(const char *fmt, ...);
#else
if( ((u64)buffer) % 8 ){
#endif
- vg_error( "buffer: %p\n", buffer );
- vg_fatal_exit_loop( "unaligned buffer" );
+ vg_fatal_error( "unaligned buffer (%p)", buffer );
}
vg_linear_allocator *alloc = vg_linear_header( buffer );
if( (alloc->cur + size) > alloc->size ){
- vg_error( "%u + %u > %u\n", alloc->cur, size, alloc->size );
- vg_fatal_exit_loop( "linear allocator overflow" );
+ vg_fatal_error( "linear allocator overflow (%u + %u > %u)\n",
+ alloc->cur, size, alloc->size );
}
if( alloc->flags & VG_MEMORY_SYSTEM )
if( (alloc->allocation_count + 1) > VG_MAX_ALLOCATIONS )
- vg_fatal_exit_loop( "Max linear allocations reached" );
+ vg_fatal_error( "Max linear allocations reached" );
void *data;
u8 *bytes = data;
for( u32 i=0; i<size; i++ ){
- bytes[i] = 0xae;
+ bytes[i] = 0xfe;
}
alloc->allocation_count ++;
#else
if( ((u64)data) % 8 ){
#endif
- vg_fatal_exit_loop( "unaligned" );
+ vg_fatal_error( "unaligned" );
}
return data;
}
if( alloc->last_alloc != data )
- vg_fatal_exit_loop( "This block has been fixed!" );
+ vg_fatal_error( "This block has been fixed!" );
if( (alloc->cur - alloc->last_alloc_size + newsize) > alloc->size )
- vg_fatal_exit_loop( "Cannot resize, overflow" );
+ vg_fatal_error( "Cannot resize, overflow" );
alloc->cur -= alloc->last_alloc_size;
alloc->cur += newsize;
if( vg_mem.use_libc_malloc && (alloc->flags & VG_MEMORY_SYSTEM) ){
data = realloc( data, newsize );
if( !data )
- vg_fatal_exit_loop( "realloc failed" );
+ vg_fatal_error( "realloc failed" );
alloc->alloc_table[ alloc->allocation_count-1 ].data = data;
alloc->last_alloc = data;
{
vg_linear_allocator *alloc = vg_linear_header( buffer );
- if( alloc->last_alloc != data )
- vg_fatal_exit_loop( "This block has been fixed!" );
+ if( alloc->last_alloc != data ){
+ vg_fatal_error( "This block has been fixed! Last alloc: %p, this: %p\n",
+ alloc->last_alloc, data );
+ }
if( vg_mem.use_libc_malloc && (alloc->flags & VG_MEMORY_SYSTEM) ){
vg_allocation_meta *meta = &alloc->alloc_table[alloc->allocation_count-1];
if( meta->type == k_allocation_type_linear )
- vg_fatal_exit_loop( "Cannot free a linear allocator in this conext" );
+ vg_fatal_error( "Cannot free a linear allocator in this conext" );
free( data );
}
vg_linear_allocator *alloc = vg_linear_header( buffer );
if( alloc->last_alloc != data )
- vg_fatal_exit_loop( "This block has been fixed!" );
+ vg_fatal_error( "This block has been fixed!" );
u32 new_size = alloc->last_alloc_size + extra;
return vg_linear_resize( buffer, data, new_size );
vg_linear_allocator *alloc = vg_linear_header( lin_alloc );
if( alloc->cur + block_size > alloc->size )
- vg_fatal_exit_loop( "Out of memory" );
+ vg_fatal_error( "Out of memory" );
if( alloc->allocation_count + 1 > VG_MAX_ALLOCATIONS )
- vg_fatal_exit_loop( "Max allocations in linear allocator" );
+ vg_fatal_error( "Max allocations in linear allocator" );
if( (flags && VG_MEMORY_SYSTEM) && (alloc->flags & VG_MEMORY_REALTIME) )
- vg_fatal_exit_loop( "Cannot declare realtime allocator inside systems"
+ vg_fatal_error( "Cannot declare realtime allocator inside systems"
" allocator" );
if( vg_mem.use_libc_malloc ){
}
alloc->cur += block_size;
- alloc->last_alloc = NULL; /* cant resize this block! */
+ alloc->last_alloc = header;
alloc->last_alloc_size = block_size;
-
alloc->allocation_count ++;
}
else{
vg_mem.scratch = vg_create_linear_allocator( vg_mem.rtmemory,
size_scratch,
VG_MEMORY_SYSTEM );
-
- vg_mem.async = vg_create_linear_allocator( NULL, 50*1024*1024,
- VG_MEMORY_REALTIME );
}
#endif /* VG_MEM_H */