Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Tipos principales

Godot tiene una colección rica de clases y plantillas que componen su núcleo, y todo está construido a base de ellas.

Esta fuente las registra en orden.

Asignación de memoria

Godot has many tricks for ensuring memory safety and tracking memory usage. Because of this, the regular C and C++ library calls should not be used. Instead, a few replacements are provided.

Para la asignación de memoria de estilo C, Godot proporciona algunos macros:

memalloc(size)
memrealloc(pointer)
memfree(pointer)

These are equivalent to the usual malloc(), realloc(), and free() of the C standard library.

Para la asignación de estilo C++, se proporcionan macros especiales:

memnew(Class)
memnew(Class(args))
memdelete(instance)

memnew_arr(Class, amount)
memdelete_arr(pointer_to_array)

These are equivalent to new, delete, new[], and delete[] respectively.

memnew/memdelete also use a little C++ magic to automatically call post-init and pre-release functions. For example, this is used to notify Objects right after they are created, and right before they are deleted.

Contenedores

Godot provides its own set of containers, which means STL containers like std::string and std::vector are generally not used in the codebase. See ¿Por qué Godot no usa STL (Standard Template Library)? for more information.

A 📜 icon denotes the type is part of Variant. This means it can be used as a parameter or return value of a method exposed to the scripting API.

Godot datatype

Closest C++ STL datatype

Comentario

String 📜

std::string

Use this as the "default" string type. String uses UTF-32 encoding to simplify processing thanks to its fixed character size.

Vector

std::vector

Use this as the "default" vector type. Uses copy-on-write (COW) semantics. This means it's generally slower but can be copied around almost for free. Use LocalVector instead where COW isn't needed and performance matters.

HashSet

std::unordered_set

Use this as the "default" set type.

AHashMap

std::unordered_map

Use this as the "default" map type. Does not preserve insertion order. Note that pointers into the map, as well as iterators, are not stable under mutations. If either of these affordances are needed, use HashMap instead.

StringName 📜

std::string

Uses string interning for fast comparisons. Use this for static strings that are referenced frequently and used in multiple locations in the engine.

LocalVector

std::vector

Closer to std::vector in semantics, doesn't use copy-on-write (COW) thus it's faster than Vector. Prefer it over Vector when copying it cheaply is not needed.

Array 📜

std::vector

Values can be of any Variant type. No static typing is imposed. Uses shared reference counting, similar to std::shared_ptr. Uses Vector<Variant> internally.

TypedArray 📜

std::vector

Subclass of Array but with static typing for its elements. Not to be confused with Packed*Array, which is internally a Vector.

Packed*Array 📜

std::vector

Alias of Vector, e.g. PackedColorArray = Vector<Color>. Only a limited list of packed array types are available (use TypedArray otherwise).

List

std::list

Linked list type. Generally slower than other array/vector types. Prefer using other types in new code, unless using List avoids the need for type conversions.

FixedVector

std::array

Vector with a fixed capacity (more similar to boost::container::static_vector). This container type is more efficient than other vector-like types because it makes no heap allocations.

Span

std::span

Represents read-only access to a contiguous array without needing to copy any data. Note that Span is designed to be a high performance API: It does not perform parameter correctness checks in the same way you might be used to with other Godot containers. Use with care. Span can be constructed from most array-like containers (e.g. vector.span()).

RBSet

std::set

Utiliza un árbol rojo-negro para un acceso más rápido.

VSet

std::flat_set

Uses copy-on-write (COW) semantics. This means it's generally slower but can be copied around almost for free. The performance benefits of VSet aren't established, so prefer using other types.

HashMap

std::unordered_map

Defensive (robust but slow) map type. Preserves insertion order. Pointers to keys and values, as well as iterators, are stable under mutation. Use this map type when either of these affordances are needed. Use AHashMap otherwise.

RBMap

std::map

Map type that uses a red-black tree to find keys. The performance benefits of RBMap aren't established, so prefer using other types.

Dictionary 📜

std::unordered_map

Keys and values can be of any Variant type. No static typing is imposed. Uses shared reference counting, similar to std::shared_ptr. Preserves insertion order. Uses HashMap<Variant> internally.

TypedDictionary 📜

std::unordered_map

Subclass of Dictionary but with static typing for its keys and values.

Pair

std::pair

Stores a single pair. See also KeyValue in the same file, which uses read-only keys.

Relocation safety

Godot's containers assume their elements are trivially relocatable.

This means that, if you store data types in it that have pointers to themselves, or are otherwise not trivially relocatable, Godot might crash. Note that storing pointers to objects that are not trivially relocatable, such as some Object subclasses, is unproblematic and supported.

The reason to assume trivial relocatability is that it allows us to make use of important optimization techniques, such as relocation by memcpy or realloc.

GH-100509 rastrea esta decisión.

Multithreading / Concurrency

Ver también

You can find more information on multithreading strategies at Usar múltiples hilos.

None of Godot's containers are thread-safe. When you expect multiple threads to access them, you must use multithread protections.

Note that some of the types listed here are also available through the bindings, but the binding types are wrapped with RefCounted (found in the CoreBind:: namespace). Prefer the primitives listed here when possible, for efficiency reasons.

Godot datatype

Closest C++ STL datatype

Comentario

Mutex

std::recursive_mutex

Recursive mutex type. Use MutexLock lock(mutex) to lock it.

BinaryMutex

std::mutex

Non-recursive mutex type. Use MutexLock lock(mutex) to lock it.

RWLock

std::shared_mutex

Read-write aware mutex type. Use RWLockRead lock(mutex) or RWLockWrite lock(mutex) to lock it.

SafeBinaryMutex

std::mutex

Recursive mutex type that can be used with ConditionVariable. Use MutexLock lock(mutex) to lock it.

ConditionVariable

std::condition_variable

Condition variable type, used with SafeBinaryMutex.

Semaphore

std::counting_semaphore

Tipo de semáforo de conteo.

SafeNumeric

std::atomic

Templated atomic type, designed for numbers.

SafeFlag

std::atomic_bool

Bool atomic type.

SafeRefCount

std::atomic

Atomic type designed for reference counting. Will refuse to increment the reference count if it is 0.

Tipos Matemáticos

Hay varios tipos de matemáticas lineales disponibles en el directorio core/math:

Ruta del nodo

Este es un tipo de dato especial utilizado para almacenar rutas en un árbol de escena y hacer referencia a ellas de manera optimizada:

RID

Los RID son identificadores de recurso. Los servidores los utilizan para hacer referencia a los datos almacenados en ellos. Los RID son opacos, lo que significa que los datos a los que hacen referencia no se pueden acceder directamente. Los RID son únicos, incluso para diferentes tipos de datos referenciados: