GObject Hint/1

if you need to store a Unix Time timestamp inside a GObject property, use an int64 as the property type.

don’t use a GTimeVal, and above all: don’t even think about adding a GType for GTimeVal inside your own project.

first of all, because all that you can do with GTimeVal you can also do it with an int64; second of all, because if everyone starts defining boxed types for types in GLib, we’ll soon start to get collisions. and, no: adding a boxed type in GLib is not a good idea — see above, re: int64.

if you need second resolution (which is fine for most operations), just use tv.tv_sec; if you need millisecond resolution (which is fine for file operations), just use:

  gint64 msecs = tv.tv_sec * 1000 + tv.tv_usec / 1000;

and if you need microsecond resolution (which is fine if you’re bordering insanity), then use:

  gint64 usecs = tv.tv_sec * G_USEC_PER_SEC + tv.tv_usec;

this blog post has been brought to you by your friendly neighbour GObject and language binding developer.

This entry was posted in Uncategorized. Bookmark the permalink.