Re: [Vala] Compact classes in HashTable



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:

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.

:M:





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