Re: [Vala] Static array initialization
- From: "Cayle Graumann" <cayle graumann gmail com>
- To: "Jürg Billeter" <j bitron ch>
- Cc: vala paldo org
- Subject: Re: [Vala] Static array initialization
- Date: Thu, 8 Mar 2007 20:11:31 -0600
Jurg,
On 3/8/07, Jürg Billeter <j bitron ch> wrote:
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
I wasn't thinking of resizing every time one by one, but in fairly
sizeable chunks of 512 or 1024 int - so using resize may actually work
for me. I'll just have to see. I'd like to see your ArrayList
implentation when you done. If your wondering what I'm working on - I
am reimplementing the speedy non-SAX XML parser Vtd-Xml from
ximpleware. There is a java and a C# implementation. They also have
a C version, however it uses an exception library based on
preprocessor macros. The Vala implementation will use signals rather
than exceptions.
Cayle in Missouri
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]