-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify that resize doesn't initialize memory #50560
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming this is true, does it not apply to all the other Pool*Arrays?
Not all but all the ones using primitives (see #43033). Added the note for Int, Byte and Real |
doc/classes/PoolByteArray.xml
Outdated
@@ -134,6 +134,7 @@ | |||
</argument> | |||
<description> | |||
Sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. | |||
[b]Note:[/b] Added elements are not automatically initialized to 0 and may contain garbage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"garbage" sounds colloquial and thus not really suitable for documentation. Or is that the official name of uninitialized memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, its not really colloquial, see e.g. "garbage collection", but in this case IMO "and may contain random values" or "previous values in memory" would be better.
Commits should be squashed together, see PR workflow. |
Concerns were addressed, but I cannot validate them myself
For the record, I checked and confirmed that those poolarrays contains random data when resized:
|
Getting all zeroes some times: "Garbage": |
Random invalid values, maybe? |
They are valid, every arrangement of bits can be interpreted as a valid int or float, etc. And they are not random. "Garbage", or "garbage values" is the technical term. |
For "random value", I've seen many people without programming background think it means "the system will generate a random value there" and wonder why it decides to make the effort to generate a random value instead of just putting a zero 🤣 If "garbage value" is colloquial, I suggest "indeterminate value". It's used in C/C++ standards to describe such values. |
I don't agree that "garbage" and "variable" are at the same level terminology wise (for the record, PVS-Studio uses I suggest "may contain garbage, i.e. indeterminate values". Edit: BTW maybe it should not say "may", but "will". It's guaranteed to be uninitialized, thus indeterminate/garbage. |
Thanks Akien and Timothyqiu. What I meant about variable is having to explain a term inside the class reference but "indeterminate value" is clear, accurate and short. |
Some users might expect resize() to initialize added elements to zero. This clarifies that it is not the case.
Thanks! |
Some users might expect resize() to initialize added elements to zero. This clarifies that it is not the case.
Only relevant to 3.x since 4.0 handles it differently