RealDocs

TArray::Reserve

function Core Since unknown
#include "Containers/Array.h"
Access: public

Description

Pre-allocates memory for at least Number elements without changing the logical size. Prevents repeated reallocations when the final element count is known in advance.

Caveats & Gotchas

  • Reserve() only grows capacity — it never shrinks it. To release excess memory, use Shrink() after removing elements.
  • Calling Reserve() does not change Num() — the array's logical size stays the same. Only Add/Emplace/etc. increase Num().
  • If Number is less than the current capacity, the call is a no-op.

Signature

void Reserve(SizeType Number)

Parameters

Name Type Description Default
Number int32 The minimum number of elements to reserve capacity for.

Return Type

void

Example

Reserve before a known-size population loop C++
TArray<FHitResult> Hits;
Hits.Reserve(32); // Expect up to 32 hits

GetWorld()->LineTraceMultiByChannel(Hits, Start, End, ECC_Visibility, Params);

// No reallocation occurred during the trace population

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.