dstring_t
3
dstring_t
data structure for dynamic string representation
#include <cds/dstring.h>
typedef struct _dstring_t {
dlink_t buffers;
int len;
int buff_size;
} dstring_t;
Description
This structure represents dynamic string. It allows concatenation of
multiple strings without worry about memory allocations.
Internaly it uses list of data buffers which are allocated
if needed. The content of dynamic string may be copied out from internal buffers
using simple function call (see ). Internal
buffers are allocated in package memory (when compiled with SER)!
This structure is used as base for simple object serialization (see ).
Members
buffers
linked list of allocated data buffers
len
whole string length
buff_size
size of newly allocated buffers
Warning - structure internals may change! For manipulation use
manipulation functions.
Example
#include <cds/dstring.h>
#include <cds/sstr.h>
int main(int argc, char **argv)
{
dstring_t str;
str_t s;
dstr_init(&str, 256);
dstr_append_zt(&str,"This is a ");
dstr_append_zt(&str,"very long ");
dstr_append_zt(&str,"string.");
if (dstr_get_str(&str, &s) == 0) {
printf("result: %.*s\n", FMT_STR(s));
str_free_content(&s);
}
dstr_destroy(&str);
return 0;
}
This will result in
result: This is a very long
string.
Todo
Create a function like sprintf.
See Also
,
,
,