reference counting using a pointer
- From: Eduardo Pérez Ureta <eperez dei inf uc3m es>
- To: gtk-list gnome org
- Subject: reference counting using a pointer
- Date: Mon, 9 Jul 2001 08:21:53 +0000
Could anyone explain me 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.
The second approach could also remember where references are (useful for
debugging).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]