Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

std.experimental.allocator.building_blocks.scoped_allocator

Sourcestd/experimental/allocator/building_blocks/scoped_allocator.d

structScopedAllocator(ParentAllocator);
ScopedAllocator delegates all allocation requests toParentAllocator.When destroyed, theScopedAllocator object automatically callsdeallocate for all memory allocated through its lifetime. (ThedeallocateAll function is also implemented with the same semantics.)
deallocate is also supported, which is where most implementation effortand overhead ofScopedAllocator go. Ifdeallocate is not needed, asimpler design combiningAllocatorList withRegion is recommended.
Examples:
import std.experimental.allocator.mallocator : Mallocator;import std.typecons : Ternary;ScopedAllocator!Mallocator alloc;writeln(alloc.empty);// Ternary.yesconst b = alloc.allocate(10);writeln(b.length);// 10writeln(alloc.empty);// Ternary.no
Allocatorparent;
IfParentAllocator is stateful,parent is a property giving access to anAffixAllocator!ParentAllocator. Otherwise,parent is an alias forAffixAllocator!ParentAllocator.instance.
enum autoalignment;
Alignment offered
size_tgoodAllocSize(size_tn);
Forwards toparent.goodAllocSize (which accounts for the management overhead).
void[]allocate(size_tn);
Allocates memory. For management it actually allocates extra memory from the parent.
boolexpand(ref void[]b, size_tdelta);
Forwards toparent.expand(b, delta).
boolreallocate(ref void[]b, size_ts);
Reallocatesb to new sizes.
Ternaryowns(void[]b);
Forwards toparent.owns(b).
booldeallocate(void[]b);
Deallocatesb.
booldeallocateAll();
Deallocates all memory allocated.
pure nothrow @nogc @safe Ternaryempty() const;
ReturnsTernary.yes if this allocator is not responsible for any memory,Ternary.no otherwise. (Never returnsTernary.unknown.)
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 00:53:53 2026

[8]ページ先頭

©2009-2026 Movatter.jp