Add documentation to Vector::reserve and Vector::reserve_exact.

This commit is contained in:
Lukas Tenbrink
2026-01-03 16:51:57 +01:00
parent b8e4523224
commit 7a3c74e739

View File

@@ -121,11 +121,20 @@ public:
return _cowdata.template resize<false>(p_size);
}
/// Reserves capacity for at least p_size total elements.
/// You can use `reserve` before repeated insertions to improve performance.
/// The capacity grows in 1.5x increments when possible, and uses `p_size`
/// exactly otherwise.
Error reserve(Size p_size) {
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
return _cowdata.reserve(p_size);
}
/// Reserves capacity for exactly p_size total elements.
/// This can be useful to reduce RAM use of large vectors, but wastes CPU
/// time if more than p_size elements are added after the `reserve_exact` call.
/// Prefer using `reserve`, unless the vector (or copies of it) will never
/// grow again after p_size elements are inserted.
Error reserve_exact(Size p_size) {
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
return _cowdata.reserve_exact(p_size);