QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
buffer.h File Reference

Provides a pool of buffers you can use whenever you need a quick buffer. More...

#include "qev.h"

Go to the source code of this file.

Macros

#define g_string_printf   qev_buffer_printf
 You have no choice: g_string_*printf() is not zero-alloc, and the ones here are. More...
 
#define g_string_vprintf   qev_buffer_vprintf
 g_string_vprintf is being hijacked
 
#define g_string_append_printf   qev_buffer_append_printf
 g_string_append_printf is being hijacked
 
#define g_string_append_vprintf   qev_buffer_append_vprintf
 g_string_append_vprintf is being hijacked
 
#define g_string_append(buff, str)   qev_buffer_append_len(buff, str, strlen(str))
 Takes the length of str at compile-time, if possible. More...
 

Functions

GString * qev_buffer_get ()
 Gets a buffer from the pool. More...
 
void qev_buffer_put (GString *buff)
 Releases a buffer to the pool. More...
 
void qev_buffer_put0 (GString **buff)
 Releases the buffer and sets the pointer to NULL. More...
 
void qev_buffer_printf (GString *buff, const gchar *format,...) G_GNUC_PRINTF(2
 The variable argument version of qev_buffer_vprintf() More...
 
void void qev_buffer_vprintf (GString *buff, const gchar *format, va_list args) G_GNUC_PRINTF(2
 glib's g_string_printf() functions are, stupidly enough, NOT zero-allocation (at least as much as appending to a growing buffer can be zero-allocation). More...
 
void void void qev_buffer_append_printf (GString *buff, const gchar *format,...) G_GNUC_PRINTF(2
 The variable argument version of qev_buffer_append_vprintf() More...
 
void void void void qev_buffer_append_vprintf (GString *buff, const gchar *format, va_list args) G_GNUC_PRINTF(2
 glib's g_string_append_printf() functions are, stupidly enough, NOT zero-allocation (at least as much as appending to a growing buffer can be zero-allocation). More...
 
void void void void void qev_buffer_ensure (GString *buff, const gsize len)
 Ensures that the string will fit at least len bytes more. More...
 
void qev_buffer_append_buff (GString *buff, const GString *other)
 Append a buffer to this buffer. More...
 
void qev_buffer_append_len (GString *buff, const gchar *str, const gsize len)
 A faster alternative to g_string_append_len() More...
 
void qev_buffer_clear (GString *buff)
 A faster alternative to g_string_truncate(str, 0) More...
 
void qev_buffer_append_uint (GString *buff, guint64 v)
 A faster alternative to g_string_printf("%lu", v). More...
 
void qev_buffer_replace_str (GString *buff, const gchar *from, const gchar *to)
 Replace the given sequence in the string with the other. More...
 

Detailed Description

Provides a pool of buffers you can use whenever you need a quick buffer.

Author
Andrew Stone andre.nosp@m.w@cl.nosp@m.ovar..nosp@m.com

Macro Definition Documentation

#define g_string_append (   buff,
  str 
)    qev_buffer_append_len(buff, str, strlen(str))

Takes the length of str at compile-time, if possible.

It's a minor but easy optimization.

#define g_string_printf   qev_buffer_printf

You have no choice: g_string_*printf() is not zero-alloc, and the ones here are.

Their functions are being wholesale replaced to use the non-zero-alloc functions provided here.

Function Documentation

void qev_buffer_append_buff ( GString *  buff,
const GString *  other 
)

Append a buffer to this buffer.

Attention
buff and other MAY NOT be the same string.
Parameters
buffThe buffer to add to
otherThe buffer to copy from.
void qev_buffer_append_len ( GString *  buff,
const gchar *  str,
const gsize  len 
)

A faster alternative to g_string_append_len()

Attention
This function ONLY uses memcpy, so it is unsafe to for str to overlap with buff->str in any way. This function is only intended to add other strings to this one.
Parameters
buffThe buffer to append to
strThe string to append
lenThe length of str
void void void qev_buffer_append_printf ( GString *  buff,
const gchar *  format,
  ... 
)

The variable argument version of qev_buffer_append_vprintf()

Parameters
buffThe buffer to append to
formatThe format
...The arguments to format
void qev_buffer_append_uint ( GString *  buff,
guint64  v 
)

A faster alternative to g_string_printf("%lu", v).

Parameters
buffThe string to append to.
vThe value to append.
void void void void qev_buffer_append_vprintf ( GString *  buff,
const gchar *  format,
va_list  args 
)

glib's g_string_append_printf() functions are, stupidly enough, NOT zero-allocation (at least as much as appending to a growing buffer can be zero-allocation).

So let's just do it the right way here.

Parameters
buffThe buffer to append to
formatThe format
argsThe arguments to format
void qev_buffer_clear ( GString *  buff)

A faster alternative to g_string_truncate(str, 0)

Parameters
buffThe buffer to clear
void void void void void qev_buffer_ensure ( GString *  buff,
const gsize  len 
)

Ensures that the string will fit at least len bytes more.

That is, ensures that the size of buff->str >= (buff->len + len + 1).

Parameters
buffThe buffer to resize
lenHow much free space to ensure is at the end of the string. In other words, (buff->allocated_len - buff->len) > len.
GString* qev_buffer_get ( )

Gets a buffer from the pool.

Attention
Buffers received from the pool must be returned to the pool with qev_buffer_put*(). Though a GString* is returned, the pool allocates its own control structures around the GString to manage its lifetime, and calling with g_string_free() WILL result in a memory leak.
void qev_buffer_printf ( GString *  buff,
const gchar *  format,
  ... 
)

The variable argument version of qev_buffer_vprintf()

Parameters
buffThe buffer to print into
formatThe format
...The arguments to format
void qev_buffer_put ( GString *  buff)

Releases a buffer to the pool.

Attention
Buffers may only be returned to the pool if they were allocated with qev_buffer_get(). Though a GString* is returned, the pool allocates its own control structures around the GString to manage its lifetime.
void qev_buffer_put0 ( GString **  buff)

Releases the buffer and sets the pointer to NULL.

Attention
Buffers may only be returned to the pool if they were allocated with qev_buffer_get(). Though a GString* is returned, the pool allocates its own control structures around the GString to manage its lifetime.
void qev_buffer_replace_str ( GString *  buff,
const gchar *  from,
const gchar *  to 
)

Replace the given sequence in the string with the other.

Parameters
buffThe buffer to replace in
fromThe string to search for
toThe string to replace with
void void qev_buffer_vprintf ( GString *  buff,
const gchar *  format,
va_list  args 
)

glib's g_string_printf() functions are, stupidly enough, NOT zero-allocation (at least as much as appending to a growing buffer can be zero-allocation).

So let's just do it the right way here.

Parameters
buffThe buffer to print into
formatThe format
argsThe arguments to format