diff options
| author | gingerBill <bill@gingerbill.org> | 2022-03-01 15:38:04 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-03-01 15:38:04 +0000 |
| commit | 18607e53cba060558b7618e2c12245b363ad2a7f (patch) | |
| tree | 06385a59fbdb7bc196f15b3d09cdd9e185284876 /core/mem/virtual/virtual_platform.odin | |
| parent | ed933b3f219407893826e30f12a3de86cb909c9f (diff) | |
Correct `alloc_from_memory_block`
Diffstat (limited to 'core/mem/virtual/virtual_platform.odin')
| -rw-r--r-- | core/mem/virtual/virtual_platform.odin | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/core/mem/virtual/virtual_platform.odin b/core/mem/virtual/virtual_platform.odin index c4211ba5e..85caa6419 100644 --- a/core/mem/virtual/virtual_platform.odin +++ b/core/mem/virtual/virtual_platform.odin @@ -4,8 +4,9 @@ package mem_virtual import sync "core:sync/sync2" Platform_Memory_Block :: struct { - block: Memory_Block, - reserved: uint, + block: Memory_Block, + committed: uint, + reserved: uint, prev, next: ^Platform_Memory_Block, } @@ -20,7 +21,8 @@ platform_memory_alloc :: proc(to_commit, to_reserve: uint) -> (block: ^Platform_ commit(raw_data(data), to_commit) block = (^Platform_Memory_Block)(raw_data(data)) - block.reserved = to_reserve + block.committed = to_commit + block.reserved = to_reserve return } @@ -52,3 +54,17 @@ platform_memory_init :: proc() { global_platform_memory_block_sentinel_set = true } } + +platform_memory_commit :: proc(block: ^Platform_Memory_Block, to_commit: uint) -> (err: Allocator_Error) { + if to_commit < block.committed { + return nil + } + if to_commit > block.reserved { + return .Out_Of_Memory + } + + + commit(block, to_commit) or_return + block.committed = to_commit + return nil +} |