On Vendredi 29 Novembre 2002 17:18, Leopold Toetsch wrote:
> > Should I use something else to have arrays of arrays?
> multiarrays are mainly intended for huge packed multi dim arrays.

Then what should I use for a 2D array?


> > ... 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.

So, a so-called MultiArray is in fact one array, but the first n elems 
are the elems of the 1st line, the next n elems are the 2nd line, etc.?

Speaking of limitations, what can hold a multiarray? Only integers, only 
strings, only pmc, a mix of everything?


> >     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())

Ok, I understand.


> 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

If I understand correctly, this means that:
* P1[0] is the size of the "flat" one-dim array. So, for a 2d array 
supporting 25 rows and 80 columns, I should set P1[0] to 80*25, right?
* P1[1] is the multidimension, plus one for the index calculation? And 
does it start at 0 or 1? If I want a 2D multiarray, should I set P1[1] 
to 2, or what? And isn't it redundant with P1[3]?
* P1[2], I can't understand what does this one stand for
* P1[3] is the packed key, telling that first dim goes from 0 to n, and 
2nd dim from 0 to m. So, if I want a 2D array of 80x25, ie (0..79, 
0..24), then I should issue the following:
       new P2, .Key
       set P2, 79          # 79 or 80?
       new P3, .Key
       set P3, 24          # 24 or 25?
       push P2, P3
       set P1[3], P2
* P1[4]: I can't understand this one, neither. And in fact it isn't used 
in t/pmc/multiarray.t


> > 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.

Well, that's pretty clear... :-(
Then, what should I use for 2d arrays that need to grow? MultiArray for 
now, and I must wait for a pmc that will allow growing and auto- 
resizing multiarray?
Will there ever be such a PMC anyway?


Thanks for the explanations,
Jerome
-- 
[EMAIL PROTECTED]

Reply via email to