Re: Floating references
- From: Chris Vine <vine35792468 gmail com>
- To: gtk-list gnome org
- Subject: Re: Floating references
- Date: Tue, 6 Jun 2017 20:29:26 +0100
On Tue, 06 Jun 2017 19:35:40 +0900
Tristan Van Berkom <tristan vanberkom codethink co uk> wrote:
On Tue, 2017-06-06 at 11:50 +0200, Stefan Salewski wrote:
But I was wondering, why for newly created objects ref count is not
just zero, so when the element is put into a container it is just
increased to one.
In a way, it already is.
Whether it is the actual ref_count that is zero, or whether there is
just a separate floating flag I think is quite immaterial; you need to
have some state to mark the floating object after g_object_new()
returns otherwise it is in an invalid state until the first call to
g_object_ref().
The fact that the count itself is 1, is mostly irrelevant.
I have to say that I have had the same thought as Stefan on this. All
other intrusive pointer implementations I have seen start at a count
of 0 on creating an object, increment the count to 1 when that object
becomes first owned, and take the change of state from 1 to 0 on the
final unreference as indicating that the object concerned needs to be
freed.
Using a separate flag for the same initial purpose seems pointless: it
is a waste of space. Possibly the original designer didn't want a count
of 0 to arise in two different circumstances (on creation and on the
final unreference), but that seems a bit weak. Surely there must have
been some other reason for it?
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]