Improve documentation related to Pool*Array value passing caveats

This commit is contained in:
Hugo Locurcio
2022-03-28 16:16:41 +02:00
parent 288370609c
commit b47466bc59
7 changed files with 102 additions and 11 deletions

View File

@@ -5,7 +5,20 @@
</brief_description>
<description>
An array specifically designed to hold integer values ([int]). Optimized for memory usage, does not fragment the memory.
[b]Note:[/b] This type is passed by value and not by reference.
[b]Note:[/b] This type is passed by value and not by reference. This means that when [i]mutating[/i] a class property of type [PoolIntArray] or mutating a [PoolIntArray] within an [Array] or [Dictionary], changes will be lost:
[codeblock]
var array = [PoolIntArray()]
array[0].push_back(1234)
print(array) # [[]] (empty PoolIntArray within an empty Array)
[/codeblock]
Instead, the entire [PoolIntArray] property must be [i]reassigned[/i] with [code]=[/code] for it to be changed:
[codeblock]
var array = [PoolIntArray()]
var pool_array = array[0]
pool_array.push_back(1234)
array[0] = pool_array
print(array) # [[1234]] (PoolIntArray with 1 element inside an Array)
[/codeblock]
[b]Note:[/b] This type is limited to signed 32-bit integers, which means it can only take values in the interval [code][-2^31, 2^31 - 1][/code], i.e. [code][-2147483648, 2147483647][/code]. Exceeding those bounds will wrap around. In comparison, [int] uses signed 64-bit integers which can hold much larger values.
</description>
<tutorials>