Initialization

Usage

use Memory.Initialization;

or

import Memory.Initialization;

Support for move-initializing and deinitializing values.

The Initialization module provides functions which enable users to move-initialize and deinitialize values.

The functionality provided by this module can be used to implement collections in a manner similar to those implemented by the Chapel standard modules (such as List or Map).

Note

Throughout documentation, the term variable also includes non-const formals, array elements, record or class fields, and tuple components.

proc needsDeinit(type t) param

Check to see if a given type needs to be deinitialized.

Arguments

t : type – A type to check for deinitialization

Returns

true if t needs to be deinitialized

Return type

param bool

proc explicitDeinit(ref arg: ?t)

Explicitly deinitialize a variable. The variable referred to by arg should be considered uninitialized after a call to this function.

Warning

At present the compiler does not account for deinitialization performed upon a call to explicitDeinit(). It should only be called when deinitialization would not occur otherwise.

Arg

A variable to deinitialize

proc moveInitialize(ref lhs, in rhs)

Move-initialize lhs with the value in rhs. The contents of lhs are not deinitialized before the move, and rhs is not deinitialized after the move.

Warning

If lhs references an already initialized variable, it will be overwritten by the contents of rhs without being deinitialized first. Call explicitDeinit() to deinitialize lhs if necessary.

Arguments
  • lhs – A variable to move-initialize, whose type matches rhs

  • rhs – A value to move-initialize from

proc moveToValue(const ref arg: ?t)

Move the contents of the variable or constant referred to by arg into a new value.

Warning

The variable or constant referred to by arg should be considered uninitialized after a call to this function.

Arguments

arg – A variable or constant to move

Returns

The contents of arg moved into a new value

proc moveSwap(ref lhs: ?t, ref rhs: t)

Swap the contents of the variables referred to by lhs and rhs. This function does not call the <=> operator. Unlike the <=> operator, moveSwap() does not perform assignment or initialization.

Arguments
  • lhs – A variable to swap

  • rhs – A variable to swap

proc moveInitializeArrayElements(ref a: [?d], dstStartIndex: a.idxType, srcStartIndex: a.idxType, numElements: int)

Move-initialize a group of array elements from a group of elements in the same array. This function is equivalent to a sequence of individual calls to moveInitialize().

Warning

This function will halt if the value of numElements is negative, or if any of the elements in dstStartIndex..#numElements or srcStartIndex..#numElements are out of bounds.

This function will halt if the ranges dstStartIndex..#numElements and srcStartIndex..#numElements intersect.

No checks will occur when the –fast or –no-checks flags are used.

Arguments
  • a – The array with source and destination elements

  • dstStartIndex : a.idxType – Destination index of elements to move-initialize

  • srcStartIndex : a.idxType – Source index of elements to move-initialize from

  • numElements : int – The number of elements to move-initialize

proc moveInitializeArrayElements(ref dstA: [] ?t, dstStartIndex: dstA.idxType, srcA: [] t, srcStartIndex: srcA.idxType, numElements: int)

Move-initialize a group of array elements from a group of elements in another array. This function is equivalent to a sequence of individual calls to moveInitialize().

Warning

This function will halt if the value of numElements is negative, or if any of the elements in dstStartIndex..#numElements or srcStartIndex..#numElements are out of bounds.

This function will halt if dstA and srcA are the same array and the ranges dstStartIndex..#numElements and srcStartIndex..#numElements intersect.

No checks will occur when the –fast or –no-checks flags are used.

Arguments
  • dstA – The array with destination elements

  • dstStartIndex : dstA.idxType – Destination index of elements to move-initialize

  • srcA : An array with the same element type as dstA.eltType – The array with source elements

  • srcStartIndex : srcA.idxType – Source index of elements to move-initialize from

  • numElements : int – The number of elements to move-initialize