Add allocated_bytes and total_capacity to allocator types - #7
Open
caspark wants to merge 4 commits into
Open
Conversation
Compute usage on demand by walking the chunk linked list: sum of previous chunk capacities (which are ~fully used) plus cursor offset in the current chunk. Zero overhead when not called, and exact once the allocator has warmed up to a single chunk. Exposed on BlinkAlloc, SyncBlinkAlloc, LocalBlinkAlloc, and accessible through Blink via allocator(). Includes 24 tests covering basics, reset, warm-up convergence, approximation error bounds, Vec/Blink adaptor usage, edge cases, and multi-threaded sync allocator tracking.
- Use minimal numbers (item_size=3, item_count=11, initial_chunk=32) - Assert exact values with descriptive failure messages - Add test_tracking_local_proxy showing shared/local interaction - Remove redundant LocalBlinkAlloc doc comments (were copy-paste of BlinkAlloc)
caspark
commented
Feb 13, 2026
| #[cfg(not(feature = "nightly"))] | ||
| use allocator_api2::alloc::{AllocError, Allocator}; | ||
| #[cfg(feature = "nightly")] | ||
| use core::alloc::{AllocError, Allocator}; |
Author
There was a problem hiding this comment.
cargo fmt changes are in a separate commit in case you want to drop them
caspark
commented
Feb 13, 2026
| use crate::SyncBlinkAlloc; | ||
|
|
||
| /// ChunkHeader has 4 usize fields: cursor, end, prev, cumulative_size. | ||
| const CHUNK_HEADER_SIZE: usize = size_of::<usize>() * 4; |
Author
There was a problem hiding this comment.
would be neater to size_of the header but it would have to be pub(crate) then
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Compute usage on demand by walking the chunk linked list: sum of previous chunk capacities (which are ~fully used) plus cursor offset in the current chunk. The result is exact once the blink allocator has been reset a few times, but is an approximation before then. Having these stats exposed is useful to figure out how much memory is used at various points of a program's execution.