memterface 1.1.0

Generic allocator API for templated code. Intended to supersede std.experimental.allocator.


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:

Memterface

Official git repository

A generic allocator API for templated code. Intended to supersede std.experimental.allocator.

If there are any allocator designs you would like to see in memterface.allocator.*, or you need a new API extension to make your allocator more awesome, then please open an issue!

Overview

Memterface provides strong guarantees to the programmer about how its allocators must behave:

  • Allocators must always have a deallocate function, and an isOwnerOf function to check whether a slice belongs to the allocator and is valid.
  • To reduce manual error-handling and ambiguity, allocate can only return null for zero-sized allocations. When an allocator cannot allocate enough memory, it must throw an error.

A simple Memterface allocator looks something like this:

struct MyAllocator{
	void[] allocate(size_t size) nothrow
	out(memory; memory.length == size)
	out(memory; (size == 0 && memory is null) || isOwnerOf(memory)){
		//return `size` bytes of allocated memory
	}
	
	void deallocate(void[] memory) nothrow
	in(isOwnerOf(memory)){
		//deallocate `memory`
	}
	
	bool isOwnerOf(void[] memory) nothrow{
		//return `true` if this allocator owns `memory`
	}
}

An allocator's functions may be static if they do not rely on any instance data, or an allocator can be implemented using polymorphism via the AllocatorInterface interface.

Extensions

Extensions to the base allocator interface are available for allocators with different needs & features:

ExtensionDescription
reallocateFor allocators with a specially-optimised way of reallocating memory.
extendFor allocators that can extend allocations in-place.
canAllocateLets allocators inform the user know when calling allocate (or reallocate) will fail. Useful for allocators with fixed pools of memory.

Documentation

For more information, inline documentation is available in the library's source code:

ModuleDescription
memterface.ifaceThe actual allocator API & how to use it.
memterface.ctorCreate valid type instances with memory from allocators.
memterface.wrapWrap allocators from std.experimental.allocator with Wrapped!T, and create wrappers over allocators with no equivalent of isOwnerOf with ImplementIsOwnerOf.
memterface.allocator.gcGCAllocator: D's built-in garbage collector.
memterface.allocator.mallocCAllocator: The C standard library's malloc.
memterface.allocator.bottomBottomAllocator: The fallback used at the bottom of a chain of fallbacks.
Authors:
  • Aya Partridge
Dependencies:
none
Versions:
1.1.0 2025-Oct-11
1.0.9 2025-Aug-31
1.0.8 2025-Aug-29
1.0.7 2025-Aug-23
1.0.6 2025-Aug-20
Show all 12 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 4 downloads this month

  • 18 downloads total

Score:
0.4
Short URL:
memterface.dub.pm