Skip to content

Modern Array Reserve

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Array › Array Container › Reserve

Reserve

Makes room for at least n elements without adding any; it never shrinks.

Syntax

Reserve( byval n as int32 )

Notes

  • O(n) — grow to at least n

Examples

#import "std/containers"
using containers

dim v as Array( of int32 )

'' Allocate once up front when the size is known
v.Reserve( 1000 )
print v.Capacity         '' 1024 -- rounded up by doubling
print v.Count            '' 0 -- Reserve allocates, it does not add elements

'' Never shrinks: a smaller request is ignored, so a push/pop loop sitting
'' on a capacity boundary cannot thrash
v.Reserve( 4 )
print v.Capacity         '' 1024

Library: Array Container
Category: Array
Documented under: Members

Clone this wiki locally