RcPtr.alloc

Constructs an object of array type ElementType including its array elements and wraps it in a RcPtr.

  1. auto alloc(AllocatorType a, Args args)
  2. auto alloc(AllocatorType a, size_t n, Args args)
    struct RcPtr
    static
    alloc
    (
    bool supportGC = platformSupportGC
    AllocatorType
    Args...
    )
    (
    AllocatorType a
    ,
    const size_t n
    ,
    auto ref Args args
    )
    if (
    isDynamicArray!ElementType
    )

Parameters

n size_t

Array length

args Args

parameters for constructor for each array element.

The array elements are constructed as if by the expression emplace!ElementType(_payload, args), where _payload is an internal pointer to storage suitable to hold an object of type ElementType. The storage is typically larger than ElementType.sizeof * n in order to use one allocation for both the control block and the each array element.

Examples

auto a = allocatorObject(Mallocator.instance);
auto arr = RcPtr!(long[], DestructorType!(typeof(a))).alloc(a, 6, -1);
assert(arr.length == 6);
assert(arr.get.length == 6);

import std.algorithm : all;
assert(arr.get.all!(x => x == -1));

for(int i = 0; i < 6; ++i)
    arr.get[i] = i;

assert(arr.get == [0, 1, 2, 3, 4, 5]);

Meta