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.
Checking the stable version of the documentation...
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 📜 |
|
Use this as the "default" string type. |
|
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 |
|
|
Use this as the "default" set type. |
|
|
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 |
|
|
Uses string interning for fast comparisons. Use this for static strings that are referenced frequently and used in multiple locations in the engine. |
|
|
Closer to |
|
Array 📜 |
|
Values can be of any Variant type. No static typing is imposed.
Uses shared reference counting, similar to |
|
Subclass of |
|
|
Alias of |
|
|
Linked list type. Generally slower than other array/vector types. Prefer using
other types in new code, unless using |
|
|
Vector with a fixed capacity (more similar to |
|
|
Represents read-only access to a contiguous array without needing to copy any data.
Note that |
|
|
Utiliza un árbol rojo-negro para un acceso más rápido. |
|
|
Uses copy-on-write (COW) semantics.
This means it's generally slower but can be copied around almost for free.
The performance benefits of |
|
|
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 |
|
|
Map type that uses a
red-black tree to find keys.
The performance benefits of |
|
|
Keys and values can be of any Variant type. No static typing is imposed.
Uses shared reference counting, similar to |
|
|
Subclass of |
|
|
Stores a single pair. See also |
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 |
|---|---|---|
|
Recursive mutex type. Use |
|
|
Non-recursive mutex type. Use |
|
|
Read-write aware mutex type. Use |
|
|
Recursive mutex type that can be used with |
|
|
Condition variable type, used with |
|
|
Tipo de semáforo de conteo. |
|
|
Templated atomic type, designed for numbers. |
|
|
Bool atomic type. |
|
|
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: