Columned
A single, contiguous, allocation for multiple arrays, such as for, structure-of-arrays.
Meant to allocate multiple arrays, that live the same lifetimes.
This reduces multiple allocations, to a single one. This may improve performance,
as multiple memory allocations may need multiple, slow, system calls.
Further, this may alleviate memory fragmentation. This crate facilitates the implementation of
columnar/structure-of-arrays data structures.
Working Principle
Guard manages a contiguous allocation of memory. Each slice has a pointer to this contiguous allocation. The following figure illustrates the working principle.
Guard
+--------+--------+
| 0x0123 | ... |
+--------+--------+
ptr
|
V
Heap +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0.1 | 3.2 | 5 | 7 | 20 | 6 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
^ ^
| |
ptr len ptr len
+--------+--------+ +--------+--------+
| 0x0123 | 2 | | 0x012b | 4 |
+--------+--------+ +--------+--------+
&mut [f32] &mut [u16]
The lifetimes of the type system will ensure that the Guard will outlive any slice.
Examples
Simple Example
use ;
Structure of Array Example
use MaybeUninit;
use ;
// The structure-of-array