英語版
このページの英語版を見る

std.experimental.allocator.mallocator

C のヒープアロケータ。
struct Mallocator;
Cのヒープアロケータ。
Examples:
auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4);
scope(exit) Mallocator.instance.deallocate(buffer);
//...
enum uint alignment;
アラインメントはplatformAlignment に等しい静的定数である。 に等しい静的定数であり、どのDデータ型に対しても適切なアライメントを保証する。
shared const pure nothrow @nogc @trusted void[] allocate(size_t bytes);

shared const pure nothrow @nogc @system bool deallocate(void[] b);

shared const pure nothrow @nogc @system bool reallocate(ref void[] b, size_t s);
上記で定義されたセマンティクスに従った標準的なアロケータ・メソッドである。この deallocatereallocateメソッドは@system 。 メソッドはメモリを移動させ、ユーザーコードにぶら下がりポインタを残す可能性があるからだ。やや逆説的だが 逆説的だが、malloc@safe 、割り当てられたメモリをリークする余裕のある安全なプログラムにしか役に立たない。 にしか役に立たない。
static shared Mallocator instance;
このアロケータ型のグローバル・インスタンスを返す。Cのヒープアロケータは スレッドセーフであるため、そのすべてのメソッドとit " 自体は shared.
struct AlignedMallocator;
OS固有のプリミティブを使用し、統一されたAPIの下で整列されたアロケータ。
Examples:
auto buffer = AlignedMallocator.instance.alignedAllocate(1024 * 1024 * 4,
    128);
scope(exit) AlignedMallocator.instance.deallocate(buffer);
//...
enum uint alignment;
デフォルトのアライメントはplatformAlignment である。
shared nothrow @nogc @trusted void[] allocate(size_t bytes);
alignedAllocate(bytes, platformAlignment) に転送する。
shared nothrow @nogc @trusted void[] alignedAllocate(size_t bytes, uint a);
使用方法 posix_memalignを使用する。 __aligned_mallocで使用する。
shared nothrow @nogc @system bool deallocate(void[] b);
呼び出し free(b.ptr)を呼び出す。 __aligned_free(b.ptr)を呼び出す。
shared nothrow @nogc @system bool reallocate(ref void[] b, size_t newSize);

shared nothrow @nogc @system bool alignedReallocate(ref void[] b, size_t s, uint a);
alignedReallocate(b, newSize, platformAlignment) に転送する。 allocate 。そうしないと、 で渡されたカスタムアライメントが失われる可能性がある。 alignedAllocate アラインメントが失われる可能性がある。
static shared AlignedMallocator instance;
このアロケータ型のグローバルインスタンスを返す。Cのヒープアロケータは スレッドセーフなので、すべてのメソッドと instance自身は shared.