英語版
このページの英語版を見る
std.experimental.allocator.building_blocks.segregator
- struct
Segregator
(size_t threshold, SmallAllocator, LargeAllocator); - 割り当てられたサイズに応じて、以下のように2つのアロケータ (SmallAllocator とLargeAllocator) の間で割り当て(および割り当て解除)をディスパッチする。 )間の割り当て(および割り当て解除)を行う。threshold 以下のアロケーションはすべて にディスパッチされる。 SmallAllocatorにディスパッチされる。それ以外はLargeAllocator にディスパッチされる。両方のアロケータがshared の場合、 のメソッドも提供される。
Segregator
もshared メソッドを提供する。Examples:import std.experimental.allocator.building_blocks.free_list : FreeList; import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.mallocator : Mallocator; alias A = Segregator!( 1024 * 4, Segregator!( 128, FreeList!(Mallocator, 0, 128), GCAllocator), Segregator!( 1024 * 1024, Mallocator, GCAllocator) ); A a; auto b = a.allocate(200); writeln(b.length); // 200 a.deallocate(b);
- enum uint
alignment
; - 提供されるアライメントは、2つのアロケータのアライメントの最小値である。
- static size_t
goodAllocSize
(size_ts
); - このメソッドは、アロケータが少なくとも1つ定義している場合にのみ定義される。 のみが定義する。良いアロケーションサイズは、 s <= threshold の場合はSmallAllocator から、そうでない場合はLargeAllocator から得られる。(アロケータ アロケータが
goodAllocSize
を定義していない場合は、このモジュールのデフォルトの の実装が適用される)。 - void[]
allocate
(size_t); - メモリは、s <= threshold の場合はSmallAllocator から取得される、 そうでなければLargeAllocator 。
- void[]
alignedAllocate
(size_t, uint); - このメソッドは、両方のアロケータが定義している場合に定義され、適切に SmallAllocator またはLargeAllocator に適切に転送する。
- bool
expand
(ref void[]b
, size_tdelta
); - このメソッドは、少なくとも一方のアロケータが定義している場合にのみ定義される。 に転送する。SmallAllocator が
expand
LargeAllocator とb.length + delta <= threshold を定義している場合、呼び出しはSmallAllocator に転送される。expand
とb.length > threshold を定義している場合、呼び出しは に転送される。 LargeAllocator に転送される。それ以外の場合、呼は以下を返す。 false. - bool
reallocate
(ref void[]b
, size_ts
); - このメソッドは、少なくとも1つのアロケータが定義している場合にのみ定義される。 が定義している場合にのみ定義される。SmallAllocator が
reallocate
とb.length <= threshold && s <= threshold を定義している場合、呼び出しは SmallAllocator に転送される。LargeAllocator がexpand と b.length > threshold && s > threshold を定義している場合、呼び出しは LargeAllocator に転送される。そうでない場合、呼び出しはfalse を返す。 - bool
alignedReallocate
(ref void[]b
, size_ts
, uinta
); - このメソッドは、少なくとも1つのアロケータが定義している場合にのみ定義される。 reallocate と同様に動作する。
- Ternary
owns
(void[]b
); - このメソッドは、両方のアロケータが定義している場合にのみ定義される。この呼び出しは 呼び出しは、b.length <= threshold の場合はSmallAllocator に、そうでない場合は LargeAllocator に転送される。
- bool
deallocate
(void[]b
); - この関数は、両方のアロケータが定義している場合にのみ定義され、次のように動作する。 に応じて適切に転送される。
b
.length. - bool
deallocateAll
(); - この関数は、両方のアロケータが定義している場合にのみ定義され、.
deallocateAll
を順番に呼び出す。 - Ternary
empty
(); - この関数は、両方のアロケータが定義している場合にのみ定義され、その関数を順番に呼び出す。 を返す。
empty
を返す。 - ref auto
allocatorForSize
(size_t s)(); - Segregator 、入れ子になったインスタンス化を含む複合アロケータでは、その中に格納されている個々のサブアロケータにアクセスすることが難しくなる。 allocatorForSize 、 の内部に入れ子になったアロケータを提供することで、タスクを単純化する。 Segregator 、特定のサイズs を担当する。
例:
alias A = Segregator!(300, Segregator!(200, A1, A2), A3); A a; static assert(typeof(a.allocatorForSize!10) == A1); static assert(typeof(a.allocatorForSize!250) == A2); static assert(typeof(a.allocatorForSize!301) == A3);
- template
Segregator
(Args...) if (Args.length > 3) - A
Segregator
のコンポジションに展開される。 要素Segregator
の構成に展開される:alias A = Segregator!( n1, A1, n2, A2, n3, A3, A4 );
この定義では、n1 バイト以下のアロケーションリクエストは に向けられる。 A1 n1 + 1 からn2 バイト(を含む)の間のリクエストは に向けられる。 n2 + 1 からn3 バイト(を含む)の間のリクエストはA2 に向けられる。 A3 n3 バイト以上のリクエストは に送られる。 A4に送られる。 ある特定の範囲を処理すべきでない場合は、適切に使用できる、NullAllocator を適切に使うことができる。Examples:import std.experimental.allocator.building_blocks.free_list : FreeList; import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.mallocator : Mallocator; alias A = Segregator!( 128, FreeList!(Mallocator, 0, 128), 1024 * 4, GCAllocator, 1024 * 1024, Mallocator, GCAllocator ); A a; auto b = a.allocate(201); writeln(b.length); // 201 a.deallocate(b);
Copyright © 1999-2024 by the D Language Foundation
DEEPL APIにより翻訳、ところどころ修正。
このページの最新版(英語)
このページの原文(英語)
翻訳時のdmdのバージョン: 2.108.0
ドキュメントのdmdのバージョン: 2.109.1
翻訳日付 :
HTML生成日時:
編集者: dokutoku