1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

docs: clarify len and cap attributes for arrays (#10724)

This commit is contained in:
JalonSolov 2021-07-09 16:53:25 -04:00 committed by GitHub
parent 075e09b10e
commit fbd6b91086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -637,11 +637,11 @@ println(nums) // `[1, 5, 3]`
```
#### Array Properties
There are two properties that control the "size" of an array:
* `len`: *length* - the number of defined elements of the array
* `cap`: *capacity* - the number of elements for which memory space has been reserved. The array can
grow up to this size without being reallocated. Usually, V takes care of
this property automatically but there are cases where the user may want to do manual
optimizations (see [below](#array-initialization)).
* `len`: *length* - the number of pre-allocated and initialized elements in the array
* `cap`: *capacity* - the amount of memory space which has been reserved for elements,
but not initialized or counted as elements. The array can grow up to this size without
being reallocated. Usually, V takes care of this property automatically but there are
cases where the user may want to do manual optimizations (see [below](#array-initialization)).
```v
mut nums := [1, 2, 3]
@ -1333,7 +1333,7 @@ When an identifier is just a single underscore, it is ignored.
##### Custom iterators
Types that implement a `next` method returning an `Option` can be iterated
with a `for` loop.
with a `for` loop.
```v
struct SquareIterator {