Re: where did the _construct functions go?



On Wed, 1 Aug 2001, Oskar Liljeblad wrote:

> On Wednesday, August 01, 2001 at 09:38, Havoc Pennington wrote:
> > 
> > Tim Janik <timj gtk org> writes: 
> > > do i need to change it's name to
> > > g_type_create_instance_dont_call_this() in order for people to get
> > > it?
> > 
> > One approach might be to document the function. ;-)
> 
> It is documented, I just missed that it was protected :).
> It would be nice though if g_type_create_instance(G_OBJECT_TYPE)
> was equivalent to g_object_new(G_OBJECT_TYPE, NULL).

nope, it wouldn't be nice, there would be no benefit in calling
g_type_create_instance() over g_object_new(), in fact, it's even
longer to type ;)

seriously though, for an example snippet:

typedef enum {
  STATE_ACTIVE = 1,
  STATE_OTHER = 2
} State;
typedef struct {
  int a, b;
  State state;
} MyStruct;

MyStruct*
my_struct_new (int a)
{
  MyStruct *m;
  
  /* allocate and zero initialize */
  m = g_malloc0 (sizeof (MyStruct));
  
  /* setup and enter valid state */
  m->a = a;
  m->state = STATE_ACTIVE;
  
  return m;
}

conceptually, g_type_create_instance() amounts to g_malloc0(),
wheres g_object_new() also incorporates /* setup and enter valid state */.

these two have to be kept distinct, by concept, it's not a matter of
API inconvenience.

> 
> Oskar Liljeblad (osk hem passagen se)
> 

---
ciaoTJ





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