Re: [Vala] Error in allocating memory



I ran into something like this using the 6.1 compiler. Don't know if
it exists in 7.*, nor did I see a bug that fit the description.

It looks like an array length problem of which the only workaround I
know is to use "resize".  External libs communicate size info
separately but I would still expect the following to work:

int[foo.alength] = foo.a;

That blows up at runtime so I use:

int [] a = {};
a.resize (foo.alength);
a = foo.a;

Is there a better way to handle this?



Example:

class Foo {
        public static int[] a = {1, 2, 3};

        public int[] aprop {
                get { return a; }
        }
        public int alength {
                get { return a.length; }
        }

        public int[] afunc () {
                return a;
        }
}

void main () {
        var foo = new Foo ();
        print ("    a: %d\n", foo.a.length);
        print ("aprop: %d\n", foo.aprop.length);
        print ("afunc: %d\n", foo.afunc ().length);
        print ("alength: %d\n", foo.alength);

        // One fix - resize the array size ahead of time
        int [] a = {};
        a.resize (foo.alength);
        a = foo.a;
        print ("resize: %d\n", a.length);

        // This blows up at runtime.
        int[foo.alength] a2 = foo.aprop;
}

Output
---------
    a: 3
aprop: -1
afunc: 0
alength: 3
resize: 3

GLib-ERROR **: gmem.c:136: failed to allocate 4294967292 bytes
aborting...
Aborted



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