Doing some heavy refactors on the container interfaces
Trying to set up their use to be more ideomatic to the core containers
This commit is contained in:
@ -50,12 +50,9 @@ array_grow_formula :: proc( value : u64 ) -> u64 {
|
||||
return result
|
||||
}
|
||||
|
||||
array_init :: proc( $ Type : typeid, allocator : Allocator ) -> ( Array(Type), AllocatorError ) {
|
||||
return array_init_reserve( Type, allocator, array_grow_formula(0) )
|
||||
}
|
||||
|
||||
array_init_reserve :: proc
|
||||
( $ Type : typeid, allocator : Allocator, capacity : u64, fixed_cap : b32 = false, dbg_name : string = "" ) -> ( result : Array(Type), alloc_error : AllocatorError )
|
||||
array_init :: proc( $Array_Type : typeid/Array($Type), capacity : u64,
|
||||
allocator := context.allocator, fixed_cap : b32 = false, dbg_name : string = ""
|
||||
) -> ( result : Array(Type), alloc_error : AllocatorError )
|
||||
{
|
||||
header_size := size_of(ArrayHeader(Type))
|
||||
array_size := header_size + int(capacity) * size_of(Type)
|
||||
@ -229,7 +226,6 @@ array_free :: proc( using self : Array( $ Type ) ) {
|
||||
|
||||
array_grow :: proc( using self : ^Array( $ Type ), min_capacity : u64 ) -> AllocatorError
|
||||
{
|
||||
// profile(#procedure)
|
||||
new_capacity := array_grow_formula( capacity )
|
||||
|
||||
if new_capacity < min_capacity {
|
||||
|
@ -138,6 +138,20 @@ is_power_of_two :: proc {
|
||||
is_power_of_two_uintptr,
|
||||
}
|
||||
|
||||
make :: proc {
|
||||
array_init,
|
||||
// hmap_chained_init,
|
||||
// hmap_zpl_init,
|
||||
|
||||
// Usual
|
||||
make_slice,
|
||||
make_dynamic_array,
|
||||
make_dynamic_array_len,
|
||||
make_dynamic_array_len_cap,
|
||||
make_map,
|
||||
make_multi_pointer,
|
||||
}
|
||||
|
||||
to_string :: proc {
|
||||
runes_to_string,
|
||||
str_builder_to_string,
|
||||
|
@ -38,7 +38,7 @@ memtracker_init :: proc ( tracker : ^MemoryTracker, allocator : Allocator, num_e
|
||||
tracker.name = name
|
||||
|
||||
error : AllocatorError
|
||||
tracker.entries, error = array_init_reserve( MemoryTrackerEntry, allocator, num_entries, dbg_name = name )
|
||||
tracker.entries, error = make( Array(MemoryTrackerEntry), num_entries, dbg_name = name, allocator = allocator )
|
||||
if error != AllocatorError.None {
|
||||
fatal("Failed to allocate memory tracker's hashmap");
|
||||
}
|
||||
|
46
code/grime/stack_fixed.odin
Normal file
46
code/grime/stack_fixed.odin
Normal file
@ -0,0 +1,46 @@
|
||||
package grime
|
||||
|
||||
//#region("Fixed Stack")
|
||||
|
||||
StackFixed :: struct ( $ Type : typeid, $ Size : u32 ) {
|
||||
idx : u32,
|
||||
items : [ Size ] Type,
|
||||
}
|
||||
|
||||
stack_clear :: #force_inline proc ( using stack : ^StackFixed( $Type, $Size)) {
|
||||
idx = 0
|
||||
}
|
||||
|
||||
stack_push :: #force_inline proc( using stack : ^ StackFixed( $ Type, $ Size ), value : Type ) {
|
||||
assert( idx < len( items ), "Attempted to push on a full stack" )
|
||||
|
||||
items[ idx ] = value
|
||||
idx += 1
|
||||
}
|
||||
|
||||
stack_pop :: #force_inline proc( using stack : ^StackFixed( $ Type, $ Size ) ) {
|
||||
assert( idx > 0, "Attempted to pop an empty stack" )
|
||||
|
||||
idx -= 1
|
||||
if idx == 0 {
|
||||
items[idx] = {}
|
||||
}
|
||||
}
|
||||
|
||||
stack_peek_ref :: #force_inline proc "contextless" ( using stack : ^StackFixed( $ Type, $ Size ) ) -> ( ^Type) {
|
||||
last_idx := max( 0, idx - 1 ) if idx > 0 else 0
|
||||
last := & items[last_idx]
|
||||
return last
|
||||
}
|
||||
|
||||
stack_peek :: #force_inline proc "contextless" ( using stack : ^StackFixed( $ Type, $ Size ) ) -> Type {
|
||||
last := max( 0, idx - 1 ) if idx > 0 else 0
|
||||
return items[last]
|
||||
}
|
||||
|
||||
stack_push_contextless :: #force_inline proc "contextless" ( stack : ^StackFixed( $Type, $Size), value : Type ) {
|
||||
items[idx] = value
|
||||
idx += 1
|
||||
}
|
||||
|
||||
//#endregion("Fixed Stack")
|
@ -24,7 +24,7 @@ string_to_runes_array :: proc( content : string, allocator := context.allocator
|
||||
{
|
||||
num := cast(u64) str_rune_count(content)
|
||||
|
||||
runes_array, alloc_error := array_init_reserve( rune, allocator, num )
|
||||
runes_array, alloc_error := make( Array(rune), num, allocator )
|
||||
if alloc_error != AllocatorError.None {
|
||||
return nil, alloc_error
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ virtual_protect :: proc "contextless" ( vmem : VirtualMemoryRegion, region : []b
|
||||
virtual_reserve :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( VirtualMemoryRegion, AllocatorError ) {
|
||||
page_size := uint(virtual_get_page_size())
|
||||
to_reserve := memory_align_formula( size, page_size )
|
||||
return virtual__reserve( base_address, to_reserve )
|
||||
return virtual_resreve__platform_impl( base_address, to_reserve )
|
||||
}
|
||||
|
||||
@(require_results)
|
||||
@ -97,7 +97,7 @@ virtual_release :: proc "contextless" ( vmem : VirtualMemoryRegion ) {
|
||||
// If the OS is not windows, we just use the library's interface which does not support base_address.
|
||||
when ODIN_OS != OS_Type.Windows {
|
||||
|
||||
virtual__reserve :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError )
|
||||
virtual_resreve__platform_impl :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError )
|
||||
{
|
||||
header_size := memory_align_formula(size_of(VirtualMemoryRegionHeader), mem.DEFAULT_ALIGNMENT)
|
||||
|
||||
|
@ -4,7 +4,7 @@ import "core:mem"
|
||||
import win32 "core:sys/windows"
|
||||
|
||||
@(require_results)
|
||||
virtual__reserve :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError )
|
||||
virtual_resreve__platform_impl :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError )
|
||||
{
|
||||
header_size := cast(uint) memory_align_formula(size_of(VirtualMemoryRegionHeader), mem.DEFAULT_ALIGNMENT)
|
||||
|
||||
|
Reference in New Issue
Block a user