Resizing of one dimensional array works fine, however, the problem is with multidimensional arrays. After entering values to an array and increasing its size, the original values are corrupted. I would expect that increasing the size of an array preserve already entered values.
See the attached example, first 100 triples are incorrect after resizing.
Problem with resizing multidimensional arrays
Moderator: Moderators
Problem with resizing multidimensional arrays
- Attachments
-
- array_resize_example.zgeproj
- example
- (969 Bytes) Downloaded 484 times
Hi Rado,
This happens because of the way array data is laid out in the memory. If you for example have a 2x2 Array which you re-size to 2x3, the same data is then accessed as follows.
A array is simply a "interface" to 1-dimensional data.
The solution would be to copy all data when you re-size a array dimension ( that is not the first ), which i think is fine for the editor .. but shouldn't happen during run-time. Re-sizing arrays is / can already be slow, and you don't want all data to be copied automatically as well. It should be up to the developer ( the user of ZGE ) to copy the data themselves if they want to do this.
K
This happens because of the way array data is laid out in the memory. If you for example have a 2x2 Array which you re-size to 2x3, the same data is then accessed as follows.
A array is simply a "interface" to 1-dimensional data.
The solution would be to copy all data when you re-size a array dimension ( that is not the first ), which i think is fine for the editor .. but shouldn't happen during run-time. Re-sizing arrays is / can already be slow, and you don't want all data to be copied automatically as well. It should be up to the developer ( the user of ZGE ) to copy the data themselves if they want to do this.
K
Thanks Kjell for explanation. I thought it is like this, but also thought that ZGE can do resizing little bit "smarter" according to my (maybe naive) expectations.
Nevermind, I reworked my 2d array of points originally defined as Points[X/Y/Z, point-number] to Points[point-number, X/Y/Z]. So to obtain X axis of 86-th point, I use Points[85,0], instead of original Points[0,85].
Nevermind, I reworked my 2d array of points originally defined as Points[X/Y/Z, point-number] to Points[point-number, X/Y/Z]. So to obtain X axis of 86-th point, I use Points[85,0], instead of original Points[0,85].