Re: [Vala] Static array initialization



On Don, 2007-03-08 at 17:48 -0600, Cayle Graumann wrote:
Speaking of array initialization - I came across an oddity the other
day in version 0.0.6 in that the following syntax would not compile.
I have not tried it with 0.0.7 yet as I am still trying to change over
my code to the new constructor syntax to test other things yet.

function x (int buffersize) {

      int[] i;
      if(buffersize>10) {
             i = new int[100];
      } else {
             i = new int[10];
      }

}

The vala compiler complained about the "int[] i" not being valid.

That's a known bug in the parser, we have to refactor it a bit to get
that working. We'll hopefully fix that for 0.0.8.

I like the fact that we can now resize arrays, but wonder at how
efficient an implementation it is.  I have some code I'm porting that
extensively uses a linked list (C# ArrayList) of integer arrays to
allow efficient array growth, and if the new resizable arrays are good
enough then I might not worry about reworking that code.

It uses g_renew which just calls realloc, that should be pretty fast in
general but it probably wouldn't be that efficient to resize an array
one by one all the time. The C# ArrayList is not a linked list, AFAICT,
but an array that gets resized in steps of different sizes, which is
fast enough for many use cases.

I'm in fact currently implementing a generic ArrayList class for Vala
that does exactly that. I've to fix some bugs in the compiler first to
get this nicely integrated, though. If you're interested in that
library, I'll cc you when I have some experimental version ready.

Jürg




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