RealDocs

TArray::CheckAddress

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

Description

Asserts that the given address does not point into the array's current backing buffer. Called internally before insertions and adds to catch the common bug of inserting a reference to an element of the same container being modified.

Caveats & Gotchas

  • The check fires when Addr falls within [GetData(), GetData() + ArrayMax) — including slack past the live elements. This means passing a pointer to a slot that is 'beyond' Num() but within capacity also triggers the assert.
  • CheckAddress is only called by single-element Insert(), Add(), and Emplace() variants. Batch overloads (Insert(const ElementType*, Count, Index)) skip this guard for performance. If you're inserting a raw pointer into an overlapping buffer you must ensure safety manually.
  • This is a debug/development guard only — the assertion is stripped in Shipping builds via checkf.

Signature

UE_FORCEINLINE_HINT void CheckAddress(const ElementType* Addr) const

Parameters

Name Type Description Default
Addr const ElementType* Address to verify is not inside this container's allocation.

Return Type

void

Example

Why CheckAddress catches self-insert bugs C++
TArray<FString> Names = {TEXT("Alice"), TEXT("Bob")};

// WRONG — inserting a reference to Names[0] into the same array.
// This triggers CheckAddress assertion in Debug builds because
// &Names[0] is inside the array's buffer.
Names.Add(Names[0]); // Crash or assert in development

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.