GithubHelp home page GithubHelp logo

s-fabian / deepsize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aeledfyr/deepsize

0.0 0.0 0.0 55 KB

A rust crate to find the total size of an object, on the stack and on the heap

License: MIT License

Rust 100.00%

deepsize's Introduction

deepsize

A trait and derive macro to recursively find the size of an object and the size of allocations that it owns.

This should work in #[no_std] environments, but requires the alloc crate.

Ownership and Reference Counting

DeepSizeOf counts all memory considered "owned" by the structure that it is finding the size of. Structures behind & and &mut references are not counted towards the total size of the structure; however, uniquely owned structures such as Box and Vec are.

Reference counted pointers (Arc, and Rc) are counted the first time that they appear, and are tracked to prevent them from being counted multiple times. The Weak variants of each are treated like references, and are not counted.

Features

  • std (enabled by default): Adds implementations of DeepSizeOf for types only found in std such as HashMap and Mutex.
  • derive (enabled by default): Adds support for a derive macro for DeepSizeOf.

deepsize also has optional support for these external crates:

  • slotmap: (version 0.4)
  • slab: (version 0.4)
  • indexmap: (version 1)
  • arrayvec: (version 0.5)
  • smallvec: (version 1)
  • hashbrown: (version 0.9)
  • chrono: (version 0.4)
  • actix: (version 0.11)
  • tokio: (version 1.1)

Example Code

use std::mem::size_of;

use deepsize::DeepSizeOf;

#[derive(DeepSizeOf)]
struct Test {
    a: u32,
    b: Box<[u8]>,
}

fn main() {
    let object = Test {
        a: 15,
        b: Box::new(*b"Hello, Wold!"),
    };

    assert_eq!(object.deep_size_of(), size_of::<Test>() + size_of::<u8>() * 12);
}

deepsize's People

Contributors

aeledfyr avatar pmnoxx avatar s-fabian avatar miguelfrde avatar qy3u avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.