Giter VIP home page Giter VIP logo

handlemanager-rs's Introduction

Handle Manager

Handle Manager is a utility for tracking available handles in a system. These are useful ways to communicate across FFI boundaries or recycle memory from pre-allocated spaces. For instance you might preallocate a certain number of particle emitters, then use the handle manager to track which particular ones are available or not. Alternatively you may just use it as a means to hand opaque handles off to scripting, plugin or FFI layers.

Policies

Handle management is augmented by setting policy enums. These are set when the manager is created and cannot be changed after IDs have been handed out.

Policy changes are particularly useful for allowing special debug modes, for situations like "track freed IDs, but don't hand out recycled IDs." Such a configuration is useful for detecting double-frees or aiding in finding stale references (ex. a script has ID#3 for a sound, which gets freed, then tries to play it again later; would result in playing the wrong sound in a release build but could be set in certain debug modes to throw errors instead.)

Notes

Handles are always a usize, so there might be circumstances that this wastes memory. Changing HangleManager to a generic could allow for smaller handle types but this comes at the cost of contributing to compile-time slowdowns.

Policy setting might be settable as a generic parameter as well. Theoretically that should allow specializing handle allocation and releasing at compile-time; that would reduce runtime overhead marginally, but also contribute to compile-time slowdowns.

Currently there are no benchmarks that prove these optimizations are necessary, but feel free to open a ticket if you have found a problem in your use case.

Freed IDs are stored in a straightforward free vector. This always works, but is not as efficient as it could be. Let n be the maximum number of handles ever valid at once, and up to O(n) memory could be used to store free handles in the worst case. This could be fixed by storing spans that are twiddled around and coalesced, bringing memory usage down to O(n/2) in the worst case.

The worst case for the current implementation is ex. 1000 handles taken out, then returned in any order. There will then be 1000 handles on the free list. The worst case for the above fix is 1000 handles taken out, then every second handle is returned. Staggered IDs could not be compressed to a simple "start/stop" span.

handlemanager-rs's People

Contributors

skrylar avatar

Watchers

 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.