Lumiera  0.pre.03
»edit your freedom«
tmpbuf.h File Reference

Go to the source code of this file.

Description

Round robin temporary buffers.

This helper provides some buffers per thread which are round-robin recycled with each use. The idea is to have fast buffers for temporal data without need for explicit heap management. There is a fixed number of buffers per thread, which will be re-used with a round-robin pattern, without any safety checks. The caller just needs to ensure not to use too much of these buffers. Typical usage is for "just printing a damn number", hand it over to a library, which will copy the data anyway.

Warning
this is the restored old version from bc989dab7a97fc69c (July 2010) (the improved version is still buggy as of 5/2011)

Definition in file tmpbuf.h.

#include <stdlib.h>

Macros

#define LUMIERA_TMPBUF_NUM   16
 Number of buffers in the ring This also defines how many concurent buffers can be in use in one thread (including nested calls) tmpbufs are only suitable for nested calls where one knows in advance how much tmpbufs might be used. More...
 

Functions

void lumiera_tmpbuf_freeall (void)
 free all buffers associated with this thread. More...
 
void * lumiera_tmpbuf_provide (size_t size)
 Query a thread local tmpbuf. More...
 
char * lumiera_tmpbuf_snprintf (size_t size, const char *fmt,...)
 Construct a string in a tmpbuf. More...
 
char * lumiera_tmpbuf_strcat3 (const char *str1, size_t str1_len, const char *str2, size_t str2_len, const char *str3, size_t str3_len)
 Concat up to 3 strings in a tmpbuf. More...
 
char * lumiera_tmpbuf_strndup (const char *src, size_t size)
 Duplicate string to a tmpbuf. More...
 
char * lumiera_tmpbuf_tr (const char *in, const char *from, const char *to, const char *def)
 Translates characters in a string, similar to the shell 'tr' utility. More...
 

Macro Definition Documentation

◆ LUMIERA_TMPBUF_NUM

#define LUMIERA_TMPBUF_NUM   16

Number of buffers in the ring This also defines how many concurent buffers can be in use in one thread (including nested calls) tmpbufs are only suitable for nested calls where one knows in advance how much tmpbufs might be used.

Warning
the value defined here must be a power of 2

Definition at line 43 of file tmpbuf.h.

Function Documentation

◆ lumiera_tmpbuf_freeall()

void lumiera_tmpbuf_freeall ( void  )

free all buffers associated with this thread.

This function is called automatically, usually one doesnt need to call it.

Definition at line 64 of file tmpbuf.c.

◆ lumiera_tmpbuf_provide()

void* lumiera_tmpbuf_provide ( size_t  size)

Query a thread local tmpbuf.

Parameters
sizeminimal needed size for the tmpbuf
Returns
the tmpbuf

Definition at line 80 of file tmpbuf.c.

Referenced by lumiera_tmpbuf_strndup().

+ Here is the caller graph for this function:

◆ lumiera_tmpbuf_strndup()

char* lumiera_tmpbuf_strndup ( const char *  src,
size_t  size 
)

Duplicate string to a tmpbuf.

Parameters
srcstring to be duplicated
sizemaximal length to be copied
Returns
temporary buffer containing a copy of the string

Definition at line 102 of file tmpbuf.c.

References lumiera_tmpbuf_provide().

Referenced by lumiera_tmpbuf_tr(), and scan_word().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_tmpbuf_snprintf()

char* lumiera_tmpbuf_snprintf ( size_t  size,
const char *  fmt,
  ... 
)

Construct a string in a tmpbuf.

Parameters
sizemaximal length for the string
fmtprintf like formatstring
...parameters
Returns
temporary buffer containing the constructed of the string

Definition at line 116 of file tmpbuf.c.

Referenced by lumiera_config_lookup_insert_default(), lumiera_tmpbuf_print_time(), and lumiera_tmpbuf_strcat3().

+ Here is the caller graph for this function:

◆ lumiera_tmpbuf_strcat3()

char* lumiera_tmpbuf_strcat3 ( const char *  str1,
size_t  str1_len,
const char *  str2,
size_t  str2_len,
const char *  str3,
size_t  str3_len 
)

Concat up to 3 strings in a tmpbuf.

Parameters
str1first string to concat or NULL
str1_lenhow much of the first string shall be used
str2second string to concat or NULL
str2_lenhow much of the second string shall be used
str3third string to concat or NULL
str3_lenhow much of the third string shall be used
Returns
temporary buffer containing the constructed of the string

Definition at line 135 of file tmpbuf.c.

References lumiera_tmpbuf_snprintf().

Referenced by lumiera_config_lookup_insert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_tmpbuf_tr()

char* lumiera_tmpbuf_tr ( const char *  in,
const char *  from,
const char *  to,
const char *  def 
)

Translates characters in a string, similar to the shell 'tr' utility.

Parameters
ininput string to be translated
fromsource character set
todestination character set
defdefault destination character when a character is not in the source set, when NULL then translation will abort on unknown characters and return NULL, when "" then unknown characters will be removed when set to a single character string, unknown characters will be replaced with this character
Returns
temporary buffer containing the constructed of the string

Definition at line 147 of file tmpbuf.c.

References lumiera_tmpbuf_strndup().

+ Here is the call graph for this function: