#include "tensorstore/data_type.h"
voidtensorstore::AllocateAndConstruct(
    
ptrdiff_t n,
    
ElementInitialization initialization,
    
DataType r);

Allocates and initializes a contiguous 1-dimensional array of n elements of type r specified at run time.

The memory must be freed by invoking r->destroy and then calling ::operator delete with an alignment of r->alignment.

On failure to allocate memory, throws std::bad_alloc, or terminates the process if exceptions are disabled.

Parameters:
ptrdiff_t n

The number of elements to allocate.

ElementInitialization initialization

The form of initialization to use.

DataType r

The element type.

Returns:

A pointer to the allocated array.

Note

For primitive types, default initialization leaves the elements uninitialized.