reference counting using a pointer
- From: Eduardo Pérez Ureta <eperez dei inf uc3m es>
- To: gtk-devel-list gnome org
- Subject: reference counting using a pointer
- Date: Sat, 30 Jun 2001 23:49:17 +0000
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]