View source code
Display the source code in std/experimental/allocator/building_blocks/scoped_allocator.d from which this
page was generated on github.
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
local clone.
Struct std.experimental.allocator.building_blocks.scoped_allocator.ScopedAllocator
ScopedAllocator
delegates all allocation requests to ParentAllocator
.
When destroyed, the ScopedAllocator
object automatically calls deallocate
for all memory allocated through its lifetime. (The deallocateAll
function is also implemented with the same semantics.)
struct ScopedAllocator(ParentAllocator)
;
deallocate
is also supported, which is where most implementation effort
and overhead of ScopedAllocator
go. If deallocate
is not needed, a
simpler design combining AllocatorList
with Region
is recommended.
Fields
Name | Type | Description |
---|---|---|
parent
|
AllocatorList | If ParentAllocator is stateful, parent is a property giving access
to an AffixAllocator!ParentAllocator . Otherwise, parent is an alias for AffixAllocator!ParentAllocator .
|
Methods
Name | Description |
---|---|
allocate
(n)
|
Allocates memory. For management it actually allocates extra memory from the parent. |
deallocate
(b)
|
Deallocates b .
|
deallocateAll
()
|
Deallocates all memory allocated. |
empty
()
|
Returns Ternary if this allocator is not responsible for any memory,
Ternary otherwise. (Never returns Ternary .)
|
expand
(b, delta)
|
Forwards to parent .
|
goodAllocSize
(n)
|
Forwards to parent (which accounts for the management
overhead).
|
owns
(b)
|
Forwards to parent .
|
reallocate
(b, s)
|
Reallocates b to new size s .
|
Example
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
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.