Landin library reference source

core/mem/allocation.ldn

1--- Allocate storage for one item and store `value` in it. Reports
2--- `out_of_memory` without returning a partial allocation.
3---
4--- Allocated objects are published only after their complete initial value
5--- has been stored. Reference-containing initial values must be retainable.
6public new: (item: type, provider: type is allocator,
7             inout state: provider, escaping value: item)
8            -> (object: ptr mut item) ! out_of_memory =
9    block: ptr mut u8 = try provider.alloc(state, sizeof item, alignof item)
10    object = ptr(usize(block))
11    object.val = value
12end new
13
14--- Free one typed allocation through its original provider. End all aliases
15--- first; resources referenced by the item are not released automatically.
16---
17--- Consumption ends this binding only. Copies and outstanding aliases remain
18--- the caller's manual-lifetime responsibility, as for the allocator itself.
19public delete: (item: type, provider: type is allocator,
20                inout state: provider, sink object: ptr mut item) -> none =
21    block: ptr mut u8 = ptr(usize(object))
22    provider.free(state, block, sizeof item)
23end delete