parry3d_f64/shape/voxels/voxels_sizeof.rs
1use super::{Voxels, VoxelsChunk, VoxelsChunkHeader};
2use crate::math::IVector;
3
4impl Voxels {
5 // TODO: support a crate like get_size2 (will require support on nalgebra too)?
6 /// An approximation of the memory usage (in bytes) for this struct plus
7 /// the memory it allocates dynamically.
8 pub fn total_memory_size(&self) -> usize {
9 size_of::<Self>() + self.heap_memory_size()
10 }
11
12 /// An approximation of the memory dynamically-allocated by this struct.
13 pub fn heap_memory_size(&self) -> usize {
14 // NOTE: if a new field is added to `Self`, adjust this function result.
15 let Self {
16 chunk_bvh,
17 chunk_headers,
18 chunks,
19 free_chunks,
20 chunk_keys,
21 voxel_size: _,
22 } = self;
23 chunks.capacity() * size_of::<VoxelsChunk>()
24 + free_chunks.capacity() * size_of::<usize>()
25 + chunk_keys.capacity() * size_of::<IVector>()
26 + chunk_headers.capacity() * (size_of::<VoxelsChunkHeader>() + size_of::<IVector>())
27 + chunk_bvh.heap_memory_size()
28 }
29}