Re: [Vala] Compact classes in HashTable
- From: Feng Yu <rainwoodman gmail com>
- To: "Michael 'Mickey' Lauer" <mickey vanille-media de>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Compact classes in HashTable
- Date: Fri, 29 May 2009 00:48:13 -0400
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]