4b5fcba0ccd8673ea8b741b8c808d5709772fb13
[platform/upstream/glib.git] / docs / reference / glib / tmpl / string_chunks.sgml
1 <!-- ##### SECTION Title ##### -->
2 String Chunks
3
4 <!-- ##### SECTION Short_Description ##### -->
5 efficient storage of groups of strings.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 String chunks are used to store groups of strings.
10 Memory is allocated in blocks, and as strings are added to the #GStringChunk
11 they are copied into the next free position in a block. When a block is
12 full a new block is allocated.
13 </para>
14 <para>
15 When storing a large number of strings, string chunks are more efficient
16 than using g_strdup() since fewer calls to <function>malloc()</function>
17 are needed, and less memory is wasted in memory allocation overheads.
18 </para>
19 <para>
20 By adding strings with g_string_chunk_insert_const() it is also possible
21 to remove duplicates.
22 </para>
23 <para>
24 To create a new #GStringChunk use g_string_chunk_new().
25 </para>
26 <para>
27 To add strings to a #GStringChunk use g_string_chunk_insert().
28 </para>
29 <para>
30 To add strings to a #GStringChunk, but without duplicating strings which are
31 already in the #GStringChunk, use g_string_chunk_insert_const().
32 </para>
33 <para>
34 To free the entire #GStringChunk use g_string_chunk_free().
35 It is not possible to free individual strings.
36 </para>
37
38 <!-- ##### SECTION See_Also ##### -->
39 <para>
40
41 </para>
42
43 <!-- ##### STRUCT GStringChunk ##### -->
44 <para>
45 An opaque data structure representing String Chunks.
46 It should only be accessed by using the following functions.
47 </para>
48
49
50 <!-- ##### FUNCTION g_string_chunk_new ##### -->
51 <para>
52 Creates a new #GStringChunk.
53 </para>
54
55 @size: the default size of the blocks of memory which are allocated to store
56 the strings. If a particular string is larger than this default size, a larger
57 block of memory will be allocated for it.
58 @Returns: a new #GStringChunk.
59
60
61 <!-- ##### FUNCTION g_string_chunk_insert ##### -->
62 <para>
63 Adds a copy of @string to the #GStringChunk.
64 It returns a pointer to the new copy of the string in the #GStringChunk.
65 The characters in the string can be changed, if necessary, though you
66 should not change anything after the end of the string.
67 </para>
68 <para>
69 Unlike g_string_chunk_insert_const(), this function does not check for
70 duplicates. Also strings added with g_string_chunk_insert() will not be
71 searched by g_string_chunk_insert_const() when looking for duplicates.
72 </para>
73
74 @chunk: a #GStringChunk.
75 @string: the string to add.
76 @Returns: a pointer to the copy of @string within the #GStringChunk.
77
78
79 <!-- ##### FUNCTION g_string_chunk_insert_const ##### -->
80 <para>
81 Adds a copy of @string to the #GStringChunk, unless the same string has
82 already been added to the #GStringChunk with g_string_chunk_insert_const().
83 </para>
84 <para>
85 This function is useful if you need to copy a large number of strings
86 but do not want to waste space storing duplicates. But you must remember
87 that there may be several pointers to the same string, and so any changes
88 made to the strings should be done very carefully.
89 </para>
90 <para>
91 Note that g_string_chunk_insert_const() will not return a pointer to a string
92 added with g_string_chunk_insert(), even if they do match.
93 </para>
94
95 @chunk: a #GStringChunk.
96 @string: the string to add.
97 @Returns: a pointer to the new or existing copy of @string within the
98 #GStringChunk.
99
100
101 <!-- ##### FUNCTION g_string_chunk_insert_len ##### -->
102 <para>
103
104 </para>
105
106 @chunk: 
107 @string: 
108 @len: 
109 @Returns: 
110
111
112 <!-- ##### FUNCTION g_string_chunk_free ##### -->
113 <para>
114 Frees all memory allocated by the #GStringChunk.
115 After calling g_string_chunk_free() it is not safe to
116 access any of the strings which were contained within it.
117 </para>
118
119 @chunk: a #GStringChunk.
120
121