Implementation

Library dependency tower for xo-alloc2

_images/ditaa-acc687863f54fdd51f65dba22d953dd7c364b4c4.png

Abstraction tower for xo-alloc2 components (simplified)

_images/ditaa-3230c335779dc9127fc344e4b77477438dd6fdb1.png

Abstraction tower for xo-alloc2 components (detailed)

_images/ditaa-f7ea8f63ed36c1b011c41fe37d1292475c11d84f.png
Polymorphic Allocator

Class

Description

AAllocator

Abstract allocator interface for runtime polymorphism

IAllocator_Any

Stub allocator interface for uninitialized variant

IAllocator_Xfer<D>

Allocator interface template for representation D

IAllocator_Impltype<D>

Lookup allocator interface for representation D

RAllocator<O>

Provide allocator methods for FOMO object O

Polymorphich Alloc Iterator

Class

Description

AAllocIterator

Abstract interface for iteration over allocs

IAllocIterator_Any

Stub alloc-iterator interface for uninitialized variant

IAllocIterator_Xfer<D>

Alloc-iterator interface template for representation D

IAllocIterator_Impltype<D>

Lookup alloc-iterator interface for representation D

RAllocIterator<D>

Provide alloc-iterator methods for FOMO object O.

Native Arena Allocator

Class

Description

ArenaConfig

Configuration for a DArena instance

DArena

VM-aware arena allocator

DArenaIterator

Iterator over DArena allocations

IAlllocator_DArena

Adapt a DArena to facet AAllocator

IAllocIterator_DArenaAllocator

Adapt a DArenaIterator to facet AAllocIterator

Auxiliary/Support Types

Class

Description

AllocError

Return type for an alloc request, with error details.

AllocInfo

An opaque allocation. Value of an alloc-iterator.

AllocHeaderConfig

Per-allocator configuration of alloc headers

AllocHeader

Per-allocation header (8 bytes)

cmpresult

Result of alloc-iterator comparison

Example Object Diagram

object rarena1<<RAllocator>>
rarena1 : iface = vtable1
rarena1 : data = darena1

object vtable1<<IAllocator_DArena_vtable>>
vtable1 : alloc()

object darena1<<DArena>>
darena1 : config
darena1 : lo
darena1 : hi
darena1 : free
darena1 : limit
darena1 : last_error

rarena1 o-- vtable1
rarena1 o-- darena1

representation for an arena allocator

Remarks:

  • When we know the allocator representation at compile time (DArena here), then we also know the interface (IAllocator_DArena). Devirtualization is easy since interface methods are all final.

  • Size of a FOMO object is two pointers; it’s natural to create such objects on the fly and pass them by value. When storing an allocator in another data structure, we only need to use the RAllocator stack if we want runtime polymorphism for the stored allocator. Otherwise can store a DArena instance.