GC-free, high-performance D library: Containers, networking, metaprogramming, memory management, utilities.
Go to file
Eugen Wissner 4834b36271 Finish DList implementation. Fixes #209
* removeBack
* insertAfter
* Diverse fixes of insertion logic
* Internal moveFront and moveBack functions
* Internal makeList function
2017-07-08 15:51:17 +02:00
source/tanya Finish DList implementation. Fixes #209 2017-07-08 15:51:17 +02:00
.editorconfig Add editorconfig 2017-05-11 13:57:24 +02:00
.gitignore Test x86-64 on Windows 2017-06-13 12:17:14 +02:00
.travis.yml Generate coverage for x86 aswell 2017-06-13 10:45:15 +02:00
appveyor.yml Test x86-64 on Windows 2017-06-13 12:17:14 +02:00
CODE_OF_CONDUCT.md Add No Code of Conduct 2017-06-19 06:11:32 +02:00
codecov.yml Remove previously deprecated modules 2017-06-30 04:19:20 +02:00
CONTRIBUTING.md Finish CONTRIBUTING.md 2017-06-21 15:05:39 +02:00
dub.json Update 2.074 compiler 2017-06-02 22:01:13 +02:00
LICENSE Initial commit 2016-08-24 18:07:18 +02:00
README.md Refer to net instead of network package in README 2017-07-05 23:11:54 +02:00

Tanya

Build status Build status codecov Dub version Dub downloads License

Tanya is a general purpose library for D programming language.

Its aim is to simplify the manual memory management in D and to provide a guarantee with @nogc attribute that there are no hidden allocations on the Garbage Collector heap. Everything in the library is usable in @nogc code. Tanya extends Phobos functionality and provides alternative implementations for data structures and utilities that depend on the Garbage Collector in Phobos.

Overview

Tanya consists of the following packages:

  • async: Event loop (epoll, kqueue and IOCP).
  • container: Queue, Array, Singly and doubly linked lists, Buffers, UTF-8 string, Hash set.
  • format: Formatting and conversion functions.
  • math: Arbitrary precision integer and a set of functions.
  • memory: Tools for manual memory management (allocators, smart pointers).
  • net: URL-Parsing, sockets, utilities.
  • os: Platform-independent interfaces to operating system functionality.

Basic usage

Allocators

Memory management is done with allocators. Instead of using new to create an instance of a class, an allocator is used:

import tanya.memory;

class A
{
    this(int arg)
    {
    }
}

A a = defaultAllocator.make!A(5);

defaultAllocator.dispose(a);

As you can see, the user is responsible for deallocation, therefore dispose is called at the end.

If you want to change the defaultAllocator to something different, you probably want to do it at the program's beginning. Or you can invoke another allocator directly. It is important to ensure that the object is destroyed using the same allocator that was used to allocate it.

What if I get an allocated object from some function? The generic rule is: If you haven't requested the memory yourself (with make), you don't need to free it.

tanya.memory.smartref contains smart pointers, helpers that can take care of a proper deallocation in some cases for you.

Exceptions

Since exceptions are normal classes in D, they are allocated and dellocated the same as described above, but:

  1. The caller is always responsible for destroying a caught exception.
  2. Exceptions are always allocated and should be always allocated with the defaultAllocator.
import tanya.memory;

void functionThatThrows()
{
    throw defaultAlocator.make!Exception("An error occurred");
}

try
{
    functionThatThrows()
}
catch (Exception e)
{
    defaultAllocator.dispose(e);
}

Containers

Arrays are commonly used in programming. D's built-in arrays often rely on the GC. It is inconvenient to change their size, reserve memory for future use and so on. Containers can help here. The following example demonstrates how tanya.container.array.Array can be used instead of int[].

import tanya.container.array;

Array!int arr;

// Reserve memory if I know that my container will contain approximately 15
// elements.
arr.reserve(15);

arr.insertBack(5); // Add one element.
arr.length = 10; // New elements are initialized to 0.

// Iterate over the first five elements.
foreach (el; arr[0 .. 5])
{
}

int i = arr[7]; // Access 7th element.

There are more containers in the tanya.container package.

Development

Supported compilers

dmd
2.074.1
2.073.2
2.072.2
2.071.2

Current status

Following modules are under development:

Feature Branch Build status
BitArray bitvector bitvector bitvector
TLS crypto crypto crypto
File IO io io io

Release management

3-week release cycle.

Deprecated features are removed after one release (in approximately 6 weeks after deprecating).

Further characteristics

  • Tanya is a native D library without any external dependencies.

  • Tanya is cross-platform. The development happens on a 64-bit Linux, but it is being tested on Windows and FreeBSD as well.

  • The library isn't thread-safe yet.