stable-structures icon indicating copy to clipboard operation
stable-structures copied to clipboard

Question: How to know how much memory is a BtreeMap using?

Open ufoscout opened this issue 1 year ago • 2 comments

Is it possible to determine the size in bytes used by a BTreeMap with unbounded data types? I have a use case where I need to remove items from the map if the total size exceeds a certain threshold.

ufoscout avatar May 29 '24 07:05 ufoscout

I don't think that's possible right now -- at least not in a clean way. I suppose it would make sense to add a size() function to the StableBTreeMap which would give you this information.

@ielashi Do you have an idea of how much work that would be?

dsarlis avatar May 31 '24 15:05 dsarlis

Correct, this information isn't exposed right now. It's actually quite easy to expose, since we already track how many pages we're using in memory. We can add that to the list of improvements for us to take on next.

ielashi avatar Jun 03 '24 09:06 ielashi