Skip to content

Clarifying description of the Capacity property in the Array class - #780

Open
iPhilip wants to merge 1 commit into
AutoHotkey:v2from
iPhilip:patch-23
Open

Clarifying description of the Capacity property in the Array class#780
iPhilip wants to merge 1 commit into
AutoHotkey:v2from
iPhilip:patch-23

Conversation

@iPhilip

@iPhilip iPhilip commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Clarifies that the Capacity property in the Array class affects the current allocated memory capacity of the array. As is, the documentation does not clearly distinguish the difference between the Length and the Capacity properties. Some users are confusing the two. For example, see this post.

The following code snippet distinguishes the two:

arr := [10, 20, 30]
MsgBox arr.Length    ; 3 — three elements
MsgBox arr.Capacity  ; 3 or more — depends on internal allocation

arr.Capacity := 100  ; pre-allocate for 100 elements (no reallocation needed as you push)
arr.Push(40)
MsgBox arr.Length    ; 4
MsgBox arr.Capacity  ; still 100

Clarifies that the Capacity property in the Array class affects the current *allocated memory* capacity of the array. As is the documentation does not clearly distinguish the difference between the Length and the Capacity properties. Some users are confusing the two.

The following code snippet distinguishes the two:

```
arr := [10, 20, 30]
MsgBox arr.Length    ; 3 — three elements
MsgBox arr.Capacity  ; 3 or more — depends on internal allocation

arr.Capacity := 100  ; pre-allocate for 100 elements (no reallocation needed as you push)
arr.Push(40)
MsgBox arr.Length    ; 4
MsgBox arr.Capacity  ; still 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant