Skip to content

add method to give just the net memory allocated #2

Description

@droundy

I currently have a function like:

fn mem_used<T>(f: impl Fn() -> T) -> (T, usize) {
    let reg = Region::new(&GLOBAL);
    let v = f();
    let stats = reg.change();
    let total = stats.bytes_allocated as i64 + stats.bytes_reallocated as i64 - stats.bytes_deallocated as i64;
    if total > 0 {
        (v, total as usize)
    } else {
        (v, 0)
    }
}

which is intended to give the total memory allocated a function, but I've found it's pretty fiddly, and wasn't so easy to figure out. It would be lovely if Stats had a method to make this kind of computation easier, for those of us who don't care about the precise way a function allocated memory, but rather how much was used.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions