Add hex support
This commit is contained in:
20
base.kl
20
base.kl
@@ -13,6 +13,11 @@ Arena :: struct
|
||||
alignment: U64
|
||||
len: SizeU
|
||||
|
||||
clamp_top_sizeu :: (val: SizeU, max: SizeU): SizeU
|
||||
if val > max
|
||||
return max
|
||||
return val
|
||||
|
||||
get_align_offset :: (size: SizeU, align: SizeU): SizeU
|
||||
mask := align - 1
|
||||
val := size & mask
|
||||
@@ -30,22 +35,21 @@ reserve :: (size: SizeU): OS_Memory
|
||||
flProtect = Windows.PAGE_READWRITE,
|
||||
dwSize = result.reserve,
|
||||
flAllocationType = Windows.MEM_RESERVE,
|
||||
lpAddress = 0,
|
||||
)->*U8
|
||||
lpAddress = 0)->*U8
|
||||
return result
|
||||
|
||||
clamp_top_sizeu :: (val: SizeU, max: SizeU): SizeU
|
||||
if val > max
|
||||
return max
|
||||
return val
|
||||
|
||||
commit :: (m: *OS_Memory, size: SizeU): Bool
|
||||
commit_size := align_up(size, OS_PAGE_SIZE)
|
||||
total_commit := m.commit + commit_size
|
||||
clamped_commit := clamp_top_sizeu(total_commit, m.reserve)
|
||||
adjusted_commit := clamped_commit - m.commit
|
||||
if adjusted_commit != 0
|
||||
result := Windows.VirtualFree(m.data->*void, 0, Windows.MEM_RELEASE)
|
||||
result := Windows.VirtualAlloc(
|
||||
lpAddress = (m.data + m.commit)->*void,
|
||||
dwSize = adjusted_commit,
|
||||
flAllocationType = Windows.MEM_COMMIT,
|
||||
flProtect = Windows.PAGE_READWRITE,
|
||||
)
|
||||
m.commit += adjusted_commit
|
||||
return true
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user