nu_resize

Resizes a slice to be of the given size and alignment. If the slice is not yet allocated, it will be.

When creating a slice with complex types you may wish to chain the resize operation with numem.lifetime.nogc_initialize.

Set length to 0 to free the buffer.

ref @nogc
T[]
nu_resize
(
T
)
(
ref T[] buffer
,
size_t length
,
int alignment = 1
)

Parameters

buffer T[]

The buffer to resize.

length size_t

The length of the buffer (in elements.)

alignment int

The alignment of the buffer (in bytes.)

Notes:

  • Resizing the buffer to be smaller than it was originally will cause the elements to be deleted; if, and only if the type is an aggregate value type (aka. struct or union) and said type has an elaborate destructor.
  • Class pointers will NOT be deleted, this must be done manually.
  • The memory allocated by nu_resize will NOT be initialized, you must chain it with numem.lifetime.nogc_initialize if the types rely on interior pointers.

Threadsafety: The underlying data will, if possible be updated atomically, however this does NOT prevent you from accessing stale references elsewhere. If you wish to access a slice across threads, you should use synchronisation primitives such as a mutex.

Return Value

Type: T[]

The resized buffer.

Meta