ページの改善
いますぐフォークしてオンライン編集し、このページのプルリクエストを送信します。
Github へのログインが必要です。 これは小さな変更に適しています。
大きな変更を加えたい場合は、通常の cloneの使用をお勧めします。
日本語版について
個人的な学習のために、dlang.orgを翻訳したサイトです。
翻訳に際して、様々なサイトを参考にしています。
std.experimental.allocator.building_blocks.scoped_allocator
- struct
ScopedAllocator(ParentAllocator); ScopedAllocatordelegates all allocation requests to ParentAllocator. When destroyed, theScopedAllocatorobject 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 ofScopedAllocatorgo. 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
- Allocator
parent; - If ParentAllocator is stateful,
parentis a property giving access to an AffixAllocator!ParentAllocator. Otherwise,parentis an alias for AffixAllocator!ParentAllocator.instance. - enum auto
alignment; - Alignment offered
- size_t
goodAllocSize(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.
- bool
expand(ref void[]b, size_tdelta); - Forwards to parent.expand(b, delta).
- bool
reallocate(ref void[]b, size_ts); - Reallocates
bto new sizes. - Ternary
owns(void[]b); - Forwards to parent.
owns(b). - bool
deallocate(void[]b); - Deallocates
b. - bool
deallocateAll(); - Deallocates all memory allocated.
- const pure nothrow @nogc @safe Ternary
empty(); - Returns Ternary.yes if this allocator is not responsible for any memory, Ternary.no otherwise. (Never returns Ternary.unknown.)
Copyright © 1999-2022 by the D Language Foundation | Page generated by
Ddoc on Wed Nov 23 08:33:49 2022