Deutsch   English   Français   Italiano  
<v3aa99$2gd26$1@news.usenet.ovh>

View for Bookmarking (what is this?)
Look up another Usenet article

From: Marcel Mueller <news.5.maazl@spamgourmet.org>
Newsgroups: comp.lang.c++
Subject: Alignment/padding issue
Date: Sat, 1 Jun 2024 14:37:39 +0200
Organization: MB-NET.NET for Open-News-Network e.V.
Message-ID: <v3f4mj$3c1ae$4@gwaiyur.mb-net.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 1 Jun 2024 12:37:39 -0000 (UTC)
Injection-Info: gwaiyur.mb-net.net;
	logging-data="3540302"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:iYgkiMtQNdMVlEmSu3vHzjto5yg= sha256:8rZjCHlTXab2EhCQbuOp6K97XnzP69WCADm5z2CSoxI=
	sha1:YXWeCQIPmn/3oW5OsfikHAdyD+I= sha256:FI1l0NfjQS7IRCd/23yovaCH+LrIIxYKr51urS1ynAY=
Content-Language: en-US
Bytes: 2260
Lines: 32

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