📄 glib-string-chunks.html
字号:
<html xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>String Chunks</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-data-types.html" title="GLib Data Types"><link rel="prev" href="glib-Strings.html" title="Strings"><link rel="next" href="glib-Arrays.html" title="Arrays"><meta name="generator" content="GTK-Doc V1.4 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Strings.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Arrays.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-String-Chunks"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">String Chunks</span></h2><p>String Chunks — efficient storage of groups of strings.</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h> <a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a>;<a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a>* <a href="glib-String-Chunks.html#g-string-chunk-new">g_string_chunk_new</a> (<a href="glib-Basic-Types.html#gsize">gsize</a> size);<a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-String-Chunks.html#g-string-chunk-insert">g_string_chunk_insert</a> (<a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a> *chunk, const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);<a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-String-Chunks.html#g-string-chunk-insert-const">g_string_chunk_insert_const</a> (<a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a> *chunk, const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);<a href="glib-Basic-Types.html#gchar">gchar</a>* <a href="glib-String-Chunks.html#g-string-chunk-insert-len">g_string_chunk_insert_len</a> (<a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a> *chunk, const <a href="glib-Basic-Types.html#gchar">gchar</a> *string, <a href="glib-Basic-Types.html#gssize">gssize</a> len);void <a href="glib-String-Chunks.html#g-string-chunk-free">g_string_chunk_free</a> (<a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a> *chunk);</pre></div><div class="refsect1" lang="en"><a name="id3154792"></a><h2>Description</h2><p>String chunks are used to store groups of strings.Memory is allocated in blocks, and as strings are added to the <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>they are copied into the next free position in a block. When a block isfull a new block is allocated.</p><p>When storing a large number of strings, string chunks are more efficientthan using <a href="glib-String-Utility-Functions.html#g-strdup"><code class="function">g_strdup()</code></a> since fewer calls to <code class="function"><code class="function">malloc()</code></code>are needed, and less memory is wasted in memory allocation overheads.</p><p>By adding strings with <a href="glib-String-Chunks.html#g-string-chunk-insert-const"><code class="function">g_string_chunk_insert_const()</code></a> it is also possibleto remove duplicates.</p><p>To create a new <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a> use <a href="glib-String-Chunks.html#g-string-chunk-new"><code class="function">g_string_chunk_new()</code></a>.</p><p>To add strings to a <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a> use <a href="glib-String-Chunks.html#g-string-chunk-insert"><code class="function">g_string_chunk_insert()</code></a>.</p><p>To add strings to a <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>, but without duplicating strings which arealready in the <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>, use <a href="glib-String-Chunks.html#g-string-chunk-insert-const"><code class="function">g_string_chunk_insert_const()</code></a>.</p><p>To free the entire <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a> use <a href="glib-String-Chunks.html#g-string-chunk-free"><code class="function">g_string_chunk_free()</code></a>.It is not possible to free individual strings.</p></div><div class="refsect1" lang="en"><a name="id3154962"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3154967"></a><h3><a name="GStringChunk"></a>GStringChunk</h3><a class="indexterm" name="id3154977"></a><pre class="programlisting">typedef struct _GStringChunk GStringChunk;</pre><p>An opaque data structure representing String Chunks.It should only be accessed by using the following functions.</p></div><hr><div class="refsect2" lang="en"><a name="id3154994"></a><h3><a name="g-string-chunk-new"></a>g_string_chunk_new ()</h3><a class="indexterm" name="id3155006"></a><pre class="programlisting"><a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a>* g_string_chunk_new (<a href="glib-Basic-Types.html#gsize">gsize</a> size);</pre><p>Creates a new <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>size</code></em> :</span></td><td>the default size of the blocks of memory which are allocated to storethe strings. If a particular string is larger than this default size, a largerblock of memory will be allocated for it.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>a new <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3155082"></a><h3><a name="g-string-chunk-insert"></a>g_string_chunk_insert ()</h3><a class="indexterm" name="id3155093"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_string_chunk_insert (<a href="glib-String-Chunks.html#GStringChunk">GStringChunk</a> *chunk, const <a href="glib-Basic-Types.html#gchar">gchar</a> *string);</pre><p>Adds a copy of <em class="parameter"><code>string</code></em> to the <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>.It returns a pointer to the new copy of the string in the <a href="glib-String-Chunks.html#GStringChunk"><span class="type">GStringChunk</span></a>.The characters in the string can be changed, if necessary, though youshould not change anything after the end of the string.</p><p>Unlike <a href="glib-String-Chunks.html#g-string-chunk-insert-const"><code class="function">g_string_chunk_insert_const()</code></a>, this function does not check forduplicates. Also strings added with <a href="glib-String-Chunks.html#g-string-chunk-insert"><code class="function">g_string_chunk_insert()</code></a> will not besearched by <a href="glib-String-Chunks.html#g-string-chunk-insert-const"><code class="function">g_string_chunk_insert_const()</code></a> when looking for duplicates.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -