Re: NM coding style regarding private gobject data

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]


Á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 accessor.

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

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