• Alignment/padding issue

    From Marcel Mueller@21:1/5 to All on Sat Jun 1 14:37:39 2024
    I have a B-Tree data structure with the following layout

    template<typename T>

    +--------------------+--------------------+----------------+
    | Leaf* SubNodes[32] | Some header fields | T Content[31]; | +--------------------+--------------------+----------------+

    For the internal API it is essential that the following slices exist:

    |<---- BaseLeaf ---->|
    |<-------------- BaseNode --------------->|
    |<---------------- Leaf ------------->| |<--------------------------- Node ----------------------->|

    BaseLeaf and BaseNode are used for the type erasure part of the
    implementation. Only Leaf and Node structures are allocated.

    The question is how to ensure a data structure that allows all slices to coexist, especially BaseNode and Leaf?

    The template part T has dynamic size and alignment. AFAIK the alignment requirement automatically applies to all structures containing T, i.e.
    Node and Leaf. Of course padding might be required between header and
    content. But how to ensure that the Padding remains the same when Node
    is allocated instead of Leaf?

    The goal is to get a minimum memory overhead of only a few bits per
    entry for large number of entries. So no virtual functions nor virtual
    base classes at node level.


    Marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)