Re: [Vala] Compact classes in HashTable





On Wed, May 27, 2009 at 5:07 AM, Michael 'Mickey' Lauer <mickey vanille-media de> wrote:
On Wednesday 27 May 2009 06:47:23 Yu Feng wrote:
> > I read about HashTable<>.full, but this won't help in my case, since I
> > can't seem to access the respective free function from Vala.
>
> One workaround is to declare the corresponding free function generated
> by vala as an external static member of the compact class.

Right, while being cumbersome, this seems to work:

[Compact]
public class Foo
{
   public Foo()
   {
       message( "foo created" );
   }
   ~Foo()
   {
       message( "foo destructed" );
   }
   [CCode (cname = "foo_free")]
   public extern void free();
}

...

foos = new HashTable<string,Foo>.full(str_hash, str_equal, g_free, Foo.free);

> > What can i do? Is Gee handling this better?
>
> Yes.

Not quite -- at least not with compact classes:

Sorry for the incomplete message..

x.vala:24.28-24.30: error: duplicating Foo instance, use unowned variable or
explicitly invoke copy method
       foos = new HashMap<string,Foo>( str_hash, str_equal );
                                 ^^^

Using a weak Foo here gets it to compile, but defeats the purpose as the
instance would get unref'd right after it gets out of scope.
 
Does it work if you pass your instance with (owned) on the insertion method of the HashMap? Te ownership will be passed into the HashMap and duplicating is avoided.
.

Yu

:M:


_______________________________________________
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]