Skip to content
etcimon edited this page Aug 17, 2026 · 3 revisions

Memory containers

This D port does not use the C++ STL. Containers and ownership come from memutils.

Type Role
Vector!T Growable array (ThreadMem allocator by default)
SecureVector!T Same, but the backing store is wiped on free (SecureMem)
Unique!T Unique owner of a class (or T* with a custom allocator). Destructor frees
RefCounted!T Shared owner used for X509Certificate, some ASN.1 objects
Unique!AutoSeededRNG rng = new AutoSeededRNG;
SecureVector!ubyte key = rng.randomVec(32);
Vector!ubyte wire;

SecureVector is for primitive bytes/ints. Higher-level Botan objects already wipe themselves; put those in Vector or Unique. Do not put Pipe / filters by value in a Vector (they hold pointers to other filters); store Unique!Filter or pointers.

On Linux/FreeBSD a small mlock pool is tried first for SecureMem, then the heap. Windows uses VirtualLock when the process is allowed to.

Tests built with memutils’ debugger (HasDebugAllocations) snapshot live bytes. checkMemutilsRepeat fails a unittest if a new of a class is not Unique-wrapped (lockless growth). Always Unique-wrap new TLSClient, new AES128, getAead(...), loadKey(...), etc.

See architecture/libstate-factory.md for how the factory hands back algorithm objects.

Clone this wiki locally