Re: [Vala] can a struct be stored in a map?



On Sat, 2012-06-30 at 12:39 -0700, Charles Hixson wrote:
My first take is that the answer is no, and I'm enough of a neophyte that

words.vala:53.29-53.33: error: `Entry' is not a supported generic type argument, use `?' to box value types

...

     HashMap<int32, Entry>     ids;

HashMap<int32, Entry?> ids;

currently I'm avoiding the problem by converting the struct to a class, 
and at least in this case that's a reasonable approach, (or, of course, 
I could probably store a pointer to the struct, but in my eyes one of 
the advantages of Vala is that it minimizes the number of times I need 
to explicitly deal with pointers).

It's generally best to void structs unless you are concerned about
performance, and even then you have to be careful.  structs are
allocated on the stack and aren't reference counted or registered with
the GObject type system, so they can be much faster when used properly.
However, they are harder to use and easy to misuse.  It is easy to
accidentally copy them, which can easily counteract their performance
benefits.


-Evan




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