persistence module doesn't properly deal with 2d array ?

BlitzMax Forums/Brucey's Modules/persistence module doesn't properly deal with 2d array ?

GW(Posted 2017) [#1]
SuperStrict 
Framework bah.persistence
Import brl.basic

Local test2d%[50,50]

test2d[5,5] = 666

Local pers:TPersist = New TPersist
Local str$ = pers.serialize( test2d )   

Local test2d_2%[,] = Int[,](pers.DeSerialize( str ))

Print test2d.Dimensions()[0]  'returns 50
Print test2d_2.Dimensions()[0] 'return 2500

Print test2d_2[5,5] 'returns 0


Am I doing something wrong?


Derron(Posted 2017) [#2]
If you check the serialized string "str$" you will recognize that it indeed missed to properly serialize the multi-array and instead stored a single-dimension-array.

TPersistence for now does not handle multi-dimensional arrays.

so arr[][] is not possible while an array of arrays is working.
arr[0] = subarr[]


Edit: I think one could extend TPersistence to store "dimension count" and then "mod" during deserialization if count was>1.
So serialization of 3x3
a b c
d e f
g h i

becomes:
size=9
dimensions=3
value=a b c d e f g h i



bye
Ron


GW(Posted 2017) [#3]
Thanks! wanted to make sure..


Derron(Posted 2017) [#4]
Just to note it down here:
I did not see a chance to use the reflection stuff to fill a [][]-multi-dim-array. Maybe this is why Brucey did not add it to persistence.mod.

A "way around" might be:
- convert the multi-dim to an array-of-arrays
- serialize
- ...
- deserialize
- convert array-of-arrays back to multi-dim



As brl.mod/reflection.mod has something in reflection.cpp:
void *bbRefArrayElementPtr( int sz,BBArray *array,int index ){
	return (char*)BBARRAYDATA( array,array->dims )+sz*index;
}


I am not sure whether passing a manual "dim"-value instead of "array->dims" (plus the approbriate offset-calculation) would allow to modify a multi-dim-array once used properly in brl.mod/reflection.mod.
Somemone might have a try ;-)




bye
Ron


grable(Posted 2017) [#5]
If you add it to a Type Field its handled correctly, so its obviously possible.

Just for fun i hacked it in by following what it did for fields, wansnt terribly difficult :p
Just know i didnt test this very long, so maybe brucey should add it himself (since he wrote it).

Heres a patch if you want to test it yourself, note it was easier making this patch than to specify where to change things, just note the filenames if you attempt to actually apply it.



GW(Posted 2017) [#6]
If you add it to a Type Field its handled correctly, so its obviously possible.

Thanks, I remember 2d arrays working in the past, but I never noticed this difference.


Derron(Posted 2017) [#7]
@ grable
Without being able to test it now: doesn't it need adjustments to the "Set"-part too? So actually filling it with content.

Had the scales part too but was not able to "fill" the array.
Or is it working because it "wraps over" to the "next" array?

I think it is because there is no check of whether "index <= length", so it just fills whatever you desire. Dunno if that works then with NG too (if structures changed or so)?

bye
Ron


grable(Posted 2017) [#8]
doesn't it need adjustments to the "Set"-part too? So actually filling it with content.
The same function is used for 1-D and N-D arrays, so i assume its already handled. Didnt look any further ;)

I think it is because there is no check of whether "index <= length", so it just fills whatever you desire. Dunno if that works then with NG too (if structures changed or so)?
Maybe, though that wouldnt matter since 2D arrays are just 1D arrays in disguise anyway.
You can verify this by checking a 2D arrays length, its the total size. Which might be why it works hehe


Derron(Posted 2017) [#9]
@ Brucey
Is it save to port it to NG or are there things to consider (differences in the structure of NG to vanilla) ?

Nonetheless I would prefer to have a command to use to fill such arrays (means modifying brl.reflection) - just to have a central place for adjustments - if needed somewhen.


bye
Ron