Git Product home page Git Product logo

datasize-rs's Introduction

data_size::<T>(&T)

The datasize crate is used for for estimating the heap memory usage of values, e.g. the number of bytes used by a Vec outside its on-stack size determined by mem::size_of.

datasize is intended for rough benchmarks, typically to find memory hogs (it won't find memory leaks, as memory that is not reachable will not be reported). While it may not give entirely accurate readings in all situations, it will quickly identify low-hanging fruit.

Example

The DataSize trait is implemented for many primitive and std types, and can be derived for structs and others:

use datasize::DataSize;

#[derive(DataSize)]
struct Example {
    count: usize,
    my_data: Vec<MyStruct>,
    warning: Option<Box<u32>>,
    #[data_size(skip)]
    skipped: Box<char>,
}

Any instance ex of the Example can now report an estimate of its heap allocation through data_size(&ex).

Other works

Other crates suitable for this task are heapsize and malloc_size_of. Unfortunately the heapsize crate has been discontinued and the malloc_size_of crate puts some rather heavy constraints on what allocator can be used.

datasize-rs's People

Contributors

marc-casperlabs avatar fizyk20 avatar afck avatar

Watchers

James Cloos avatar  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.