summaryrefslogtreecommitdiffstats
path: root/libnetdata/string/README.md
blob: b1c6e61c375ba8868ac8635e22147d2c58fac786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!--
title: "String"
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/string/README.md
sidebar_label: "String"
learn_status: "Published"
learn_topic_type: "Tasks"
learn_rel_path: "Developers/libnetdata libraries"
-->

# STRING

STRING provides a way to allocate and free text strings, while de-duplicating them.

It can be used similarly to libc string functions:

 - `strdup()` and `strdupz()` become `string_strdupz()`.
 - `strlen()` becomes `string_strlen()` (and it does not walkthrough the bytes of the string).
 - `free()` and `freez()` become `string_freez()`.

There is also a special `string_dup()` function that increases the reference counter of a STRING, avoiding the
index lookup to find it.

Once there is a `STRING *`, the actual `const char *` can be accessed with `string2str()`.

All STRING should be constant. Changing the contents of a `const char *` that has been acquired by `string2str()` should never happen.