Closed novacrazy closed 4 years ago
This seems reasonable to me. Would you like to make a pull request?
I'm not familiar with the codebase and reasoning for things enough to be confident I could write a safe implementation in the time I have. However, if you would be willing outline what it would take to make a safe implementation of such a function, I can give it a shot.
The dealloc_chunk_list
helper function shows how you can iterate over each chunk. Implementing this new method should be basically the same as that, but instead of deallocating each chunk, summing each chunk's size (example of getting a chunk's size here, this could be factored out to a helper method on ChunkFooter
).
Is that enough to get you started? Anything I can clear up?
I'm working with an application that prints diagnostic messages after running an operation to show how much memory was used during that operation, then proceeds on with the next operation. However, because the next operation relies on memory allocated in the previous operation, there are still active immutable borrows from the
Bump
allocator at the point where diagnostic information should be logged. Therefore, I cannot simply usearena.iter_allocated_chunks().map(|chunk| chunk.len()).sum()
to return the allocated size, because that requires a mutable borrow.Would you be willing to add a method for querying such information from an immutable
Bump
instance? Something likeBump::allocated_bytes(&self) -> usize