[gst-devel] fixing Gstbuffer

vishnu at pobox.com vishnu at pobox.com
Thu Sep 27 15:09:04 CEST 2001


Inline vs. macros:

1] This is not a question of performance.  There is *no* difference
in code generation.

2] Encapsulation.  C++ FAQ S9.2: "... [inline] lets you have the
safety of encapsulation along with the speed of direct access. ..."

Good encapsulation is an essential property of easy to maintain code.

(Also, separating lvalue & rvalue access enhances encapsulation.  However,
this could be done equal well using macros or inline.)

3] It is trival to switch inline ON (for releases) or OFF
(for development).

Q: Why switch inline off?

A: "the definition of an inline function must be placed in an
include file for the class, while the definition of an ordinary
function may be placed in its own separate file.  ... the
implementation of an inline function can require comprehensive
re-compiling when the definition is changed."

4] It is easier to add assertions to an inline function:

void gst_buffer_set_data (GstBuffer *buf, gchar *data, size_t size)
{
  g_return_if_fail (buf);
  g_return_if_fail (data);
  g_return_if_fail (buf->data == NULL);

  buf->data = buf;
  buf->size = size;
}

vs.

#define GST_BUFFER_SET_DATA(buf, data, size) STMT_START { \
  ... etc ... \
  } STMT_END

(Bleargh)

Summary
=======

There are no disadvantages of using inline functions, except the time
it would take to apply & debug the diff (which might also reveal some
bugs).  The advantages are:

o better encapsulation -- opaque GstBuffer
o switch inline on/off
o easier to add assertions

So what are the disadvantages again?

-- 
Victory to the Divine Mother!!
  http://sahajayoga.org




More information about the gstreamer-devel mailing list