util/memory.spice
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | public type IMemoryManager interface { | ||
| 4 | public f<heap byte*> allocate(unsigned long); | ||
| 5 | public p deallocate(heap byte*&); | ||
| 6 | } | ||
| 7 | |||
| 8 | 2113 | public type DefaultMemoryManager struct : IMemoryManager {} | |
| 9 | |||
| 10 | 157979 | public f<heap byte*> DefaultMemoryManager.allocate(unsigned long size) { | |
| 11 | 157979 | Result<heap byte*> allocation = sAlloc(size); | |
| 12 | // Take the block out of the result: the caller becomes its owner, so the result must not free it on the way out | ||
| 13 | 315958 | return allocation.unwrapAndMove(); | |
| 14 | 157979 | } | |
| 15 | |||
| 16 | 151868 | public p DefaultMemoryManager.deallocate(heap byte*& ptr) { | |
| 17 | 151868 | sDealloc(ptr); | |
| 18 | 151868 | } | |
| 19 |