makeMultidimensionalArray

Allocates a multidimensional array of elements of type T.

version(HasDRuntime)
makeMultidimensionalArray
(
T
Allocator
size_t N
)
(
auto ref Allocator alloc
,
size_t[N] lengths...
)

Parameters

N

number of dimensions

T

element type of an element of the multidimensional arrat

alloc Allocator

the allocator used for getting memory

lengths size_t[N]

static array containing the size of each dimension

Return Value

Type: auto

An N-dimensional array with individual elements of type T.

Examples

import stdx.allocator.mallocator : Mallocator;

auto mArray = Mallocator.instance.makeMultidimensionalArray!int(2, 3, 6);

// deallocate when exiting scope
scope(exit)
{
    Mallocator.instance.disposeMultidimensionalArray(mArray);
}

assert(mArray.length == 2);
foreach (lvl2Array; mArray)
{
    assert(lvl2Array.length == 3);
    foreach (lvl3Array; lvl2Array)
        assert(lvl3Array.length == 6);
}

Meta