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 using
			a local clone.
		
	std.experimental.allocator.building_blocks.scoped_allocator
- structScopedAllocator(ParentAllocator);
- ScopedAllocatordelegates all allocation requests to ParentAllocator. When destroyed, the- ScopedAllocatorobject automatically calls deallocate for all memory allocated through its lifetime. (The deallocateAll function is also implemented with the same semantics.)deallocate is also supported, which is where most implementation effort and overhead of- ScopedAllocatorgo. If deallocate is not needed, a simpler design combining AllocatorList with Region is recommended.Examples:- import std.experimental.allocator.mallocator : Mallocator; import std.typecons : Ternary; ScopedAllocator!Mallocator alloc; writeln(alloc.empty); // Ternary.yes const b = alloc.allocate(10); writeln(b.length); // 10 writeln(alloc.empty); // Ternary.no - Allocatorparent;
- If ParentAllocator is stateful,parentis a property giving access to an AffixAllocator!ParentAllocator. Otherwise,parentis an alias for AffixAllocator!ParentAllocator.instance.
- enum autoalignment;
- Alignment offered
- size_tgoodAllocSize(size_tn);
- Forwards to parent.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 to parent.expand(b, delta).
- boolreallocate(ref void[]b, size_ts);
- Reallocatesbto new sizes.
- Ternaryowns(void[]b);
- Forwards to parent.owns(b).
- booldeallocate(void[]b);
- Deallocatesb.
- booldeallocateAll();
- Deallocates all memory allocated.
- pure nothrow @nogc @safe Ternaryempty() const;
- Returns Ternary.yes if this allocator is not responsible for any memory, Ternary.no otherwise. (Never returns Ternary.unknown.)
 
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:28:19 2025