I'd like to open a discussion on having a SizeOf trait that takes into account dynamically allocated memory.
assert_eq!(vec![1u32].size_of(), 28 /* 24 + 4 */);
Would return the normal
mem::size_of + the total pointed to data. This data should use the capacity and not the
len(), because the intent is to get the total resident size of an object. This does not include kernel memory, so file descriptors will have a size_of that is just the bytes of the fd.
The use-case is to debug big structures in long-running programs in order to ensure that there are no space leaks, as well as general debugging and to get a sense of where the bulk of data is located. This can be a useful tool in monitoring an application without needing to use outside tools.
When it comes to shared memory, perhaps
SizeOf::size_of can return two numbers (u64 /owned/, u64 /shared/), shared bytes and owned bytes. Meaning that an
Rc<u32> with a reference count of 1 will return
(12, 0), whilst shared it would return