Git Product home page Git Product logo

fixed-typed-arena's Introduction

fixed-typed-arena

An arena that allocates values of a single type (similar to typed-arena) using chunks of memory that have a configurable fixed size. This enables it to perform allocations in non-amortized O(1) (constant) time.

Other arena implementations, like typed-arena, are optimized for throughput: they allocate chunks of memory with exponentially increasing sizes, which results in amortized constant-time allocations.

fixed-typed-arena is optimized for latency: it allocates chunks of memory with a fixed, configurable size, and individual value allocations are performed in non-amortized constant time.

This crate depends only on core and alloc, so it can be used in no_std environments that support alloc.

Example

use fixed_typed_arena::Arena;
struct Item(u64);

let arena = Arena::<_, 128>::new();
let item1 = arena.alloc(Item(1));
let item2 = arena.alloc(Item(2));
item1.0 += item2.0;

assert_eq!(item1.0, 3);
assert_eq!(item2.0, 2);

References

Items allocated by an Arena can contain references with the same life as the arena itself, including references to other items, but the crate feature dropck_eyepatch must be enabled. This requires Rust nightly, as fixed-typed-arena must use the eponymous unstable language feature.

Alternatively, you may be able to use a ManuallyDropArena instead.

ManuallyDropArena

This crate also provides ManuallyDropArena, which is like Arena but returns references of any lifetime, including 'static. The advantage of this type is that it can be used without being borrowed, but it comes with the tradeoff that it will leak memory unless the unsafe drop method is called.

Iteration

fixed-typed-arena’s arena types allow iteration over all allocated items. Safe mutable iteration is provided for Arena, and safe immutable iteration is provided for all arena types if Options::Mutable is false. Unsafe mutable and immutable iteration is provided for all arena types regardless of options.

Documentation

Documentation is available on docs.rs.

License

fixed-typed-arena is licensed under version 3 of the GNU General Public License, or (at your option) any later version. See LICENSE.

Contributing

By contributing to fixed-typed-arena, you agree that your contribution may be used according to the terms of fixed-typed-arena’s license.

fixed-typed-arena's People

Contributors

taylordotfish avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ajunlonglive

fixed-typed-arena's Issues

ManuallyDropArena::drop shadowed by Drop::drop

ManuallyDropArena::drop is supposed to be called to prevent memory leaks. Having a &mut self-Parameter suggests one should call it as an instance method. That however resolves to std::ops::Drop::drop. This is a no-op and a compile error; the suggested fix of using std::mem::drop is also a no-op and not what one wants.

Can the method be renamed, e.g. to manually_drop, to prevent this mistake?

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.