Cache-Friendly B+Tree Nodes with Dynamic Fanout
5 hours ago
- #Memory Layout
- #Performance Optimization
- #B+Tree
- B+Tree nodes require contiguous memory blocks for high performance, avoiding std::vector due to indirection.
- The 'struct hack' or flexible array member technique allows dynamic sizing of node entries in C/C++.
- C++11 supports flexible array members as 'arrays of unknown bound' when declared last in a struct.
- Placement new is used to construct B+Tree nodes in preallocated memory buffers for contiguous layout.
- Manual memory management is required, including careful destruction and deallocation to prevent leaks.
- Derived classes cannot add new members without risking data corruption due to memory layout constraints.
- Using raw arrays means reimplementing vector-like functionality, increasing complexity and maintenance.
- The implementation implicitly requires trivially copyable types, limiting generic use with complex types like std::string.