File naming convention change
This commit is contained in:
45
modules/Arena.core
Normal file
45
modules/Arena.core
Normal file
@@ -0,0 +1,45 @@
|
||||
OS :: #import "Windows.core"
|
||||
Base :: #import "Base.core"
|
||||
ArenaDI: U64
|
||||
|
||||
ADDITIONAL_COMMIT_SIZE :: 1024*1024
|
||||
DEFAULT_RESERVE_SIZE :: 1024*1024*1024
|
||||
DEFAULT_ALIGNMENT :: 8
|
||||
|
||||
Arena :: struct
|
||||
di: U64 // @debug_id
|
||||
memory: OS.Memory
|
||||
alignment: U64
|
||||
len: U64
|
||||
|
||||
Init :: (a: *Arena)
|
||||
a.memory = OS.Reserve(DEFAULT_RESERVE_SIZE)
|
||||
a.alignment = DEFAULT_ALIGNMENT
|
||||
a.di = ArenaDI++
|
||||
// a.allocator.proc = arena_allocator_proc
|
||||
|
||||
PushSize :: (a: *Arena, size: Base.SizeU): *void
|
||||
generous_size := size + a.alignment
|
||||
if a.len + generous_size > a.memory.commit
|
||||
if a.memory.reserve == 0
|
||||
Init(a)
|
||||
result := OS.Commit(&a.memory, generous_size + ADDITIONAL_COMMIT_SIZE)
|
||||
Assert(result == true)
|
||||
a.len = Base.AlignUp(a.len, a.alignment)
|
||||
Assert(a.memory.reserve > a.len + a.memory.commit)
|
||||
result: *void = a.memory.data + a.len
|
||||
a.len += size
|
||||
return result
|
||||
|
||||
// @todo: Make this compile time thing!!!
|
||||
// This probably will wait till polymorphism stuff
|
||||
// something like this:
|
||||
// PushType :: (a: *Arena, type: $T): *T
|
||||
//
|
||||
PushType :: (a: *Arena, type: Type): *void
|
||||
type_info := get_type_info(type)
|
||||
Assert(type_info != 0)
|
||||
return PushSize(a, type_info.size->Base.SizeU)
|
||||
|
||||
Release :: (a: *Arena)
|
||||
OS.Release(&a.memory)
|
||||
Reference in New Issue
Block a user