You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
It might be useful to understand how many bytes in memory a particular datastructure occupies.
If doesn't have any heap-allocated storage, figuring out the answer is easy: it's just std::mem::size_of.
However for data structures which include vectors, maps, boxes, etc, size_of will account only for (comparatively insignificant) stack part of the storage.
One approach to the problem is servo/heapsize, which communicates with the allocator to learn about which blocks of memory are allocated. This is a relatively precise approach, because it accounts for allocator's own overheads, but it requires the use of jemalloc.
A potentially more robust but less precise approach is to walk the datastructure recursively (that is, iterate all the vectors, hash maps, etc) and sum size_of. Looks like this can be done with a proc macro which would custom-derive the following trait:
traitDeepSizeOf{/// Returns an estimation of a total size of memory owned by the object,/// including heap-managed storage./// This is an estimation and not a precise result, because it /// doesn't account for allocator's overhead. fndeep_size_of(&self) -> usize;}