Jerome Quelin wrote:
Hi,
I'd like to use multi-arrays, but I can't understand how they're working. I looked at $PARROT/t/pmc/multiarray.t, but it's a bit obscure.
underdocumented
Could you help me to understand them please? Or are they deprecated?
Yes/No
Should I use something else to have arrays of arrays?
multiarrays are mainly intended for huge packed multi dim arrays.
... What are the limitations of multiarrays? I've read in classes/multiarray.pmc that multiarrays can only grow in their _last_ direction: is there a multidimensionnal pmc that can grow on whatever the dimesion?
Yes/no. The first-1 dimensions are used for index calculation.
About multiarray, I tried the following, and it works, but please help me to understand what I wrote:
new P2, .Key
set P2, 10
new P3, .Key
set P3, 5
push P2, P3
# Ok, I can understand that I'm building its width and height with # P2 and P3, and concatenate all the keys in one "multidimensinal" # key.
key_append would be a better term (s. classes/key.pmc:push()) - it creates a chained key.
new P1, .PerlArray
# I understand that building a multiarray requires parameters, # that we provide in a list (does multiarray require a PerlArray, # or may I use something else?)
Array or PerlArray are both fine. Actually any PMC, that supports - get_elements, get_integer_keyed_int and get_pmc_keyed_int (s. list.c:list_new_init())
set P1[0], 0 # what does this param means? set P1[1], 200 # what does this param means?
s. docs/pdds/pdd02_vtable2.pod and the usage of these params in list.c /* * list_new_init uses these initializers: * 0 ... size (set initial size of list) * 1 ... array dimensions (multiarray) * 2 ... type (overriding type parameter) * 3 ... item_size for enum_type_sized * 4 ... items_per_chunk so above lines use key 0, value 200 i.e. set size to 200.
set P1[2], 1 # what does this param means? set P1[3], P2 # The dimensions of the multiarray?
Yes
How can I make the multiarray grow? Is it self expandable, like the PerlArray (that is, accessing an element out of bounds make the PerlArray grow to fit till that new bound)?
As the definition of Multiarray is (classes/multiarray.pmc): pmclass MultiArray extends Array { it has the same growing policy as the Array class i.e. none.
Jerome, who'd like to understand...
I hope so, leo