Re: [Vala] Multidimensional arrays - help with using them.



On Fri, 2009-04-03 at 23:54 +0200, Leonti Bielski wrote:
For me tt works only for accessing elements.
For example:

int[,] some_array = new [2,2];

Makes 2x2 array of ints.

int something = some_array[0,0];
But I still cannot resize it :(

No you can't. array.resize only works for 1d array. It produces wrong
ccode for multidimension array.

I would suggest write your own resizable 2d array.

struct Array2D {
        /*read-only*/
        public int NX;
        public int NY;
        private int[] storage;

        public Array2D(int NX, int NY);
        public int get(int x, int y);
        public set(int x, int y, int value);
        public void resize(int NNX, int NNY);
}

Yu

Leonti

On Fri, Apr 3, 2009 at 11:46 PM, Yu Feng <rainwoodman gmail com> wrote:
I remember back in some versions

array[1, 2] works

Yu
On Fri, 2009-04-03 at 21:05 +0200, Leonti Bielski wrote:
It's gotta be a way to do it :(
Maybe by using lists or something similar?

Leonti

On Fri, Apr 3, 2009 at 8:01 PM, lariamat <interflug1 gmx net> wrote:
Hello
I guess, it is a bug.
There are several issues with multidimensional arrays:
http://bugzilla.gnome.org/show_bug.cgi?id=548428
http://bugzilla.gnome.org/show_bug.cgi?id=548429
http://bugzilla.gnome.org/show_bug.cgi?id=576611
Also using arrays by reference is not working.
Regards,
lariamat


Am Freitag, den 03.04.2009, 18:48 +0200 schrieb Leonti Bielski:
Hello!
I need to use multidimensional array of ints, so this is what I do:

int[][] some_array = {}; //declaring an array of int[]
int[] some = {1,2,3}; // declaring array of ints
some_array += some; // adding this array to 2D array - this works

some_array[0] = some; // this doesn't work
some_array[0] += 2; //this doesn't work

Why those last 2 examples don't work?

What I need to do is to add some values to existing inner array of
multidimensional one (as in second non-working example).
How do I do that?

Leonti
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list


_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list


_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]