Re: Simple boxing



On Wed, Nov 03, 2004 at 05:28:10PM +0100, Sven Neumann wrote:
> > time before I found this out.  I'd like some
> > G_TYPE_STRING_DONT_DUPLICATE_IT_LIKE_MAD and
> > G_TYPE_OBJECT_DONT_REFERENCE_IT_LIKE_MAD column types.
> 
> If you know your strings are const or can be treated as const while
> they are in the treestore, you can of course just treat them as
> pointers. Having a dedicated type for this wouldn't really make things
> any better or worse.

This is very true, because the better thing is not what can
be achieved with G_TYPE_POINTER.  There are four possible
approaches to ownership (making a copy can be replaced with
increasing refcount below):

1. Model owns the value (_set() makes a copy)
   and protects it (_get() gives you your own copy)

   This is how it works, when one uses the dedicated types.

2. Model owns the value (_set() makes a copy)
   and lends it when asked (_get() simply passes the object)

   This is what I normally want, but it's [normally]
   impossible.

3. Model doesn't own the value (_set() doesn't make a copy)
   and passes what you gave it (_get() simply passes the object)

   This can be achieved with G_TYPE_POINTER.

4. Model doesn't own the value (_set() doesn't make a copy)
   but protects it (_get() gives you your own copy)

   This is probably something one rarely wants.

So we have 1 (recommended) and 3 (possible), but I want 2.
I want 2 because it's good when the model owns things so
I can put constant or nonconstant strings there, etc., and
have to care only at the time of storing them.  But OTOH
I very very rarely need to get a string I can modify in
place, and when I do I can make a copy myself.  So with 2
I'd have the least number of things I have to care of, and
it seems to be the most natural mode for me (I'm aware from
GValue viewpoint it may not be so).

Unfortunately, this is purely theoretical matter anyway...

Yeti


--
Dynamic IP address is not a crime.



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