Re: [Vala] Abuse of unowned?
- From: Abderrahim Kitouni <a kitouni gmail com>
- To: Pg Dr Hj Norjaidi bin Pg Tuah <norjaidi tuah ubd edu bn>
- Cc: "vala-list gnome org" <vala-list gnome org>
- Subject: Re: [Vala] Abuse of unowned?
- Date: Tue, 08 Mar 2011 19:44:08 +0100
Hello,
في ث، 08-03-2011 عند 02:49 +0000 ، كتب Pg Dr Hj Norjaidi bin Pg Tuah:
The following code crashes when compiled with 0.11.6
due to an attempt to deallocate the static string "bar"
(https://bugzilla.gnome.org/show_bug.cgi?id=642350).
struct Foo {
public string foo;
public string bar;
}
void main() {
Foo f = Foo() {foo = "foo", bar = N_("bar")};
}
As a work around, I change the struct strings to
unowned. Thus:
struct Foo {
public unowned string foo;
public unowned string bar;
}
That seems to work. But I'm apprehensive here.
Is my workaround safe? Am I abusing "unowned"?
I'd say you should just take care, your "workaround" is not inherently
unsafe, and isn't really an abuse (I'd call that aggressive
optimisation). You should make sure that the strings you assign to these
fields aren't going to be freed somewhere else. For example, if they are
always static strings, you should be fine.
HTH,
Abderrahim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]