Re: NM coding style regarding private gobject data

On Wed, 2015-04-29 at 12:36 +0200, Alex Puchades wrote:
Hi, it seems the opaque pointer is not faster anymore [1] and, as you
said, wastes one pointer of memory, so what about
nm_type_name_get_instance_private? [1]



Interesting. Thank you for the link.

G_DEFINE_TYPE_WITH_PRIVATE() was added ~only~ in glib 2.38.
We would have to bump our min-version requirement for that.

But my point wasn't performance (or the waste of a pointer instance).
And it wasn't the burden of #define'ing NM_TYPE_NAME_GET_PRIVATE().

It's my personal annoyance with the verboseness of:

  NM_TYPE_NAME_GET_PRIVATE (self)->my_field
  nm_type_name_get_instance_private (self)->my_field



Bonus point: it's easier in gdb/debugger.


Álex Puchades

El 29/04/2015 12:00, "Thomas Haller" <thaller redhat com> escribió:
        in NM code, we tend to have gobject (duhh) with private data.
        We almost always define a macro NM_TYPE_NAME_GET_PRIVATE() as
        I think this long name is quite cumbersome to write. It's a
        bit redeemed
        as we often cache that pointer in a @priv member, but you
        still have to
           NMTypeNamePrivate *priv = NM_TYPE_NAME_GET_PRIVATE (self);
        to almost all methods.
        What do you think about registering an opaque "priv" pointer
        in the
        public struct instead?
        Something like
        /* nm-device.h */
        struct _NMDevicePrivate;
        typedef struct {
            GObject parent;
            struct _NMDevicePrivate *priv;
        } NMDevice;
        /* nm-device.c */
        typedef struct _NMDevicePrivate NMDevicePrivate;
        struct _NMDevicePrivate {
        #define NM_DEVICE_GET_PRIVATE(self) (self->priv)
        so, we can still continue to use NM_DEVICE_GET_PRIVATE(self),
        but a IMO
        nicer way would be just "self->priv".
        It even has better runtime performance (but consumes one
        pointer more
        Any opinions?
        networkmanager-list mailing list
        networkmanager-list gnome org

Attachment: signature.asc
Description: This is a digitally signed message part

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