I'm building an index tree based on a bplus tree in Rust and have so far used a definition for parent nodes as:
struct Parent<T : std::fmt::Debug> {
subtree_count : [usize; Arity],
children : [*mut ParentOrLeaf<T>; Arity],
used : usize,
}
On my 64 bit computer with Arity=8 that works out to a total memory requirement of 136 bytes. I'm using std::alloc::Layout::new and std::alloc::alloc to allocate this structure. But I'm worried that being just slightly larger than a power of two (136 > 128) that the malloc library will end up allocating 256 bytes for this data structure instead of just 136. Since this is a container type, wasting half the memory allocated is unacceptable.
std::alloc::Layout::new::<Parent<T>>().align() reports a layout of 8 as expected.
How much memory will this structure actually take up when it is allocated?
If so much memory is wasted, I could change subtree_count : [usize; Arity] to subtree_count : [usize; Arity-1], which would make the total memory 128. Then redo all of the optimized logic of my library to handle the change. But before I do, I want to make sure that is actually necessary.