RealDocs

TArray::AddUninitialized

function Core Since 4.0
#include "Containers/Array.h"
Access: public Specifiers: inline

Description

Grows the array by Count elements without constructing them, returning the index of the first new slot. Use when you will immediately overwrite every new element with placement-new or a bulk memory operation.

Caveats & Gotchas

  • The new elements contain garbage memory — reading them before writing will produce undefined behaviour. You must construct every added element before any code path that could read it.
  • Not appropriate for types with non-trivial constructors (FString, TArray, UObject-derived, etc.). Use Add() or Emplace() for those. This is a performance primitive for POD data and hand-rolled serialization.
  • Returns the index of the first new element (old Num()), NOT the count. This is a common source of bugs when callers expect a bool or new-size return.
  • A two-overload design exists: no-argument AddUninitialized() is aggressively inlined and optimised for the single-element hot path; the Count-argument version routes through a less-inlined growth path.

Signature

UE_FORCEINLINE_HINT SizeType AddUninitialized(SizeType Count = 1)

Parameters

Name Type Description Default
Count SizeType Number of elements to allocate space for. 1

Return Type

SizeType

Example

Bulk-appending POD data from a raw buffer C++
void AppendRawFloats(TArray<float>& Out, const float* Src, int32 Count)
{
    const int32 StartIndex = Out.AddUninitialized(Count);
    FMemory::Memcpy(Out.GetData() + StartIndex, Src, Count * sizeof(float));
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.