handle 0.1.0

D library for handles


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Handle

A D library for handles. Handles are a fast, compact, and serializable alternative to pointers. Further more, handles are memory safe and will never dangle, and loose handles will never cause memory leaks.

Handles are a fast and light-weight alternative to conventional or reference-counted pointers in high performance systems such as game engines.

A Short Example

Below is a brief example of handles used to store strings. Any type can be used, however.

import handle;

void main()
{
    auto manager = new HandleManager!string;
    
    // Handles are easy to use.
    auto hello = manager.add("Hello World");
    assert(manager[handle] == "Hello World");
    
    // Handles are easy to serialize.
    uint packed = cast(uint) hello;
    auto handle = Handle!string(packed);
    
    // Handles will never dangle.
    manager.remove(handle);
    assert(manager[handle] is null);
}

Capacity

Internally, the HandleManager class operates on a static array of predefined size (as a performance optimization). The default capacity of a HandleManager is 4096 (2 ^^ 12), but it accepts a second template argument as an override. For example,

void main()
{
    // Allocate enough storage for 500 handles.
    auto manager = new HandleManager!(string, 500);

    static assert(manager.capacity == 500);
    
    // . . .
}

License

MIT

Authors:
  • Mihail-K
Dependencies:
none
Versions:
0.1.0 2016-Apr-17
~master 2016-Apr-17
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 57 downloads total

Score:
0.8
Short URL:
handle.dub.pm