reference counting using a pointer



Why don't you use:
void g_io_channel_ref (GIOChannel **channel);
instead of:
void g_io_channel_ref (GIOChannel *channel);

With the current approach
I use:
GIOChannel* iochannel = NULL;
GIOChannel* iochannelnew = NULL;
_code_
if (iochannel != NULL) {
  g_io_channel_unref(iochannel);
  iochannel == NULL;
}
iochannel = g_io_channel_unix_new(fd);
_code_
if (iochannelnew != NULL) {
  g_io_channel_unref(iochannelnew);
  iochannelnew == NULL;
}
g_io_channel_ref(iochannel); iochannelnew = iochannel;
_code_
if (iochannel != NULL) {
  g_io_channel_unref(iochannel);
  iochannel == NULL;
}

much of the code above should be cut when gcc optimizes

with the approach I say:
GIOChannel* iochannel = NULL;
GIOChannel* iochannelnew = NULL;
_code_
g_io_channel_unix_new(&iochannel, fd);
_code_
g_io_channel_ref(&iochannel, &iochannelnew);
_code_
g_io_channel_unref(&iochannel);

this should be as fast as above if those functions are defined as macros




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