Problem with resizing multidimensional arrays

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Problem with resizing multidimensional arrays

Post by Rado1 »

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.
Attachments
array_resize_example.zgeproj
example
(969 Bytes) Downloaded 475 times
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

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.

Image

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
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

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].
Post Reply