2
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
4
<!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
5
<!ENTITY version SYSTEM "version.xml">
7
<refentry id="GMemoryOutputStream">
9
<refentrytitle role="top_of_page" id="GMemoryOutputStream.top_of_page">GMemoryOutputStream</refentrytitle>
10
<manvolnum>3</manvolnum>
11
<refmiscinfo>GIO Library</refmiscinfo>
15
<refname>GMemoryOutputStream</refname>
16
<refpurpose>Streaming output operations on memory chunks</refpurpose>
19
<refsynopsisdiv id="GMemoryOutputStream.synopsis" role="synopsis">
20
<title role="synopsis.title">Synopsis</title>
24
#include <gio/gio.h>
26
<link linkend="gpointer">gpointer</link> (<link linkend="GReallocFunc">*GReallocFunc</link>) (<link linkend="gpointer">gpointer</link> data,
27
<link linkend="gsize">gsize</link> size);
28
<link linkend="GMemoryOutputStream-struct">GMemoryOutputStream</link>;
29
<link linkend="GOutputStream">GOutputStream</link> * <link linkend="g-memory-output-stream-new">g_memory_output_stream_new</link> (<link linkend="gpointer">gpointer</link> data,
30
<link linkend="gsize">gsize</link> size,
31
<link linkend="GReallocFunc">GReallocFunc</link> realloc_function,
32
<link linkend="GDestroyNotify">GDestroyNotify</link> destroy_function);
33
<link linkend="gpointer">gpointer</link> <link linkend="g-memory-output-stream-get-data">g_memory_output_stream_get_data</link> (<link linkend="GMemoryOutputStream">GMemoryOutputStream</link> *ostream);
34
<link linkend="gsize">gsize</link> <link linkend="g-memory-output-stream-get-size">g_memory_output_stream_get_size</link> (<link linkend="GMemoryOutputStream">GMemoryOutputStream</link> *ostream);
35
<link linkend="gsize">gsize</link> <link linkend="g-memory-output-stream-get-data-size">g_memory_output_stream_get_data_size</link>
36
(<link linkend="GMemoryOutputStream">GMemoryOutputStream</link> *ostream);
40
<refsect1 id="GMemoryOutputStream.object-hierarchy" role="object_hierarchy">
41
<title role="object_hierarchy.title">Object Hierarchy</title>
43
<link linkend="GObject">GObject</link>
44
+----<link linkend="GOutputStream">GOutputStream</link>
45
+----GMemoryOutputStream
51
<refsect1 id="GMemoryOutputStream.implemented-interfaces" role="impl_interfaces">
52
<title role="impl_interfaces.title">Implemented Interfaces</title>
54
GMemoryOutputStream implements
55
<link linkend="GSeekable">GSeekable</link>.</para>
59
<refsect1 id="GMemoryOutputStream.properties" role="properties">
60
<title role="properties.title">Properties</title>
62
"<link linkend="GMemoryOutputStream--data">data</link>" <link linkend="gpointer">gpointer</link> : Read / Write / Construct Only
63
"<link linkend="GMemoryOutputStream--data-size">data-size</link>" <link linkend="gulong">gulong</link> : Read
64
"<link linkend="GMemoryOutputStream--destroy-function">destroy-function</link>" <link linkend="gpointer">gpointer</link> : Read / Write / Construct Only
65
"<link linkend="GMemoryOutputStream--realloc-function">realloc-function</link>" <link linkend="gpointer">gpointer</link> : Read / Write / Construct Only
66
"<link linkend="GMemoryOutputStream--size">size</link>" <link linkend="gulong">gulong</link> : Read / Write / Construct Only
72
<refsect1 id="GMemoryOutputStream.description" role="desc">
73
<title role="desc.title">Description</title>
75
<link linkend="GMemoryOutputStream"><type>GMemoryOutputStream</type></link> is a class for using arbitrary
76
memory chunks as output for GIO streaming output operations.</para>
81
<refsect1 id="GMemoryOutputStream.details" role="details">
82
<title role="details.title">Details</title>
83
<refsect2 id="GReallocFunc" role="function">
84
<title>GReallocFunc ()</title>
85
<indexterm zone="GReallocFunc"><primary sortas="ReallocFunc">GReallocFunc</primary></indexterm><programlisting><link linkend="gpointer">gpointer</link> (*GReallocFunc) (<link linkend="gpointer">gpointer</link> data,
86
<link linkend="gsize">gsize</link> size);</programlisting>
88
Changes the size of the memory block pointed to by <parameter>data</parameter> to
89
<parameter>size</parameter> bytes.
92
The function should have the same semantics as <link linkend="realloc"><function>realloc()</function></link>.</para>
94
</para><variablelist role="params">
95
<varlistentry><term><parameter>data</parameter> :</term>
96
<listitem><simpara> memory block to reallocate
97
</simpara></listitem></varlistentry>
98
<varlistentry><term><parameter>size</parameter> :</term>
99
<listitem><simpara> size to reallocate <parameter>data</parameter> to
100
</simpara></listitem></varlistentry>
101
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a pointer to the reallocated memory
102
</simpara></listitem></varlistentry>
103
</variablelist></refsect2>
104
<refsect2 id="GMemoryOutputStream-struct" role="struct">
105
<title>GMemoryOutputStream</title>
106
<indexterm zone="GMemoryOutputStream-struct"><primary sortas="MemoryOutputStream">GMemoryOutputStream</primary></indexterm><programlisting>typedef struct _GMemoryOutputStream GMemoryOutputStream;</programlisting>
108
Implements <link linkend="GOutputStream"><type>GOutputStream</type></link> for arbitrary memory chunks.</para>
111
<refsect2 id="g-memory-output-stream-new" role="function">
112
<title>g_memory_output_stream_new ()</title>
113
<indexterm zone="g-memory-output-stream-new"><primary sortas="memory_output_stream_new">g_memory_output_stream_new</primary></indexterm><programlisting><link linkend="GOutputStream">GOutputStream</link> * g_memory_output_stream_new (<link linkend="gpointer">gpointer</link> data,
114
<link linkend="gsize">gsize</link> size,
115
<link linkend="GReallocFunc">GReallocFunc</link> realloc_function,
116
<link linkend="GDestroyNotify">GDestroyNotify</link> destroy_function);</programlisting>
118
Creates a new <link linkend="GMemoryOutputStream"><type>GMemoryOutputStream</type></link>.
121
If <parameter>data</parameter> is non-<link linkend="NULL--CAPS"><literal>NULL</literal></link>, the stream will use that for its internal storage.
122
If <parameter>realloc_fn</parameter> is non-<link linkend="NULL--CAPS"><literal>NULL</literal></link>, it will be used for resizing the internal
123
storage when necessary. To construct a fixed-size output stream,
124
pass <link linkend="NULL--CAPS"><literal>NULL</literal></link> as <parameter>realloc_fn</parameter>.
127
<informalexample><programlisting>
128
/* a stream that can grow */
129
stream = g_memory_output_stream_new (NULL, 0, realloc, free);
131
/* another stream that can grow */
132
stream2 = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
134
/* a fixed-size stream */
136
stream3 = g_memory_output_stream_new (data, 200, NULL, free);
137
</programlisting></informalexample></para>
139
</para><variablelist role="params">
140
<varlistentry><term><parameter>data</parameter> :</term>
141
<listitem><simpara> pointer to a chunk of memory to use, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
142
</simpara></listitem></varlistentry>
143
<varlistentry><term><parameter>size</parameter> :</term>
144
<listitem><simpara> the size of <parameter>data</parameter>
145
</simpara></listitem></varlistentry>
146
<varlistentry><term><parameter>realloc_function</parameter> :</term>
147
<listitem><simpara> a function with <link linkend="realloc"><function>realloc()</function></link> semantics (like <link linkend="g-realloc"><function>g_realloc()</function></link>)
148
to be called when <parameter>data</parameter> needs to be grown, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
149
</simpara></listitem></varlistentry>
150
<varlistentry><term><parameter>destroy_function</parameter> :</term>
151
<listitem><simpara> a function to be called on <parameter>data</parameter> when the stream is
152
finalized, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
153
</simpara></listitem></varlistentry>
154
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> A newly created <link linkend="GMemoryOutputStream"><type>GMemoryOutputStream</type></link> object.
155
</simpara></listitem></varlistentry>
156
</variablelist></refsect2>
157
<refsect2 id="g-memory-output-stream-get-data" role="function">
158
<title>g_memory_output_stream_get_data ()</title>
159
<indexterm zone="g-memory-output-stream-get-data"><primary sortas="memory_output_stream_get_data">g_memory_output_stream_get_data</primary></indexterm><programlisting><link linkend="gpointer">gpointer</link> g_memory_output_stream_get_data (<link linkend="GMemoryOutputStream">GMemoryOutputStream</link> *ostream);</programlisting>
161
Gets any loaded data from the <parameter>ostream</parameter>.
164
Note that the returned pointer may become invalid on the next
165
write or truncate operation on the stream.</para>
167
</para><variablelist role="params">
168
<varlistentry><term><parameter>ostream</parameter> :</term>
169
<listitem><simpara> a <link linkend="GMemoryOutputStream"><type>GMemoryOutputStream</type></link>
170
</simpara></listitem></varlistentry>
171
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> pointer to the stream's data
172
</simpara></listitem></varlistentry>
173
</variablelist></refsect2>
174
<refsect2 id="g-memory-output-stream-get-size" role="function">
175
<title>g_memory_output_stream_get_size ()</title>
176
<indexterm zone="g-memory-output-stream-get-size"><primary sortas="memory_output_stream_get_size">g_memory_output_stream_get_size</primary></indexterm><programlisting><link linkend="gsize">gsize</link> g_memory_output_stream_get_size (<link linkend="GMemoryOutputStream">GMemoryOutputStream</link> *ostream);</programlisting>
178
Gets the size of the currently allocated data area (availible from
179
<link linkend="g-memory-output-stream-get-data"><function>g_memory_output_stream_get_data()</function></link>). If the stream isn't
180
growable (no realloc was passed to <link linkend="g-memory-output-stream-new"><function>g_memory_output_stream_new()</function></link>) then
181
this is the maximum size of the stream and further writes
182
will return <link linkend="G-IO-ERROR-NO-SPACE--CAPS"><literal>G_IO_ERROR_NO_SPACE</literal></link>.
185
Note that for growable streams the returned size may become invalid on
186
the next write or truncate operation on the stream.
189
If you want the number of bytes currently written to the stream, use
190
<link linkend="g-memory-output-stream-get-data-size"><function>g_memory_output_stream_get_data_size()</function></link>.</para>
192
</para><variablelist role="params">
193
<varlistentry><term><parameter>ostream</parameter> :</term>
194
<listitem><simpara> a <link linkend="GMemoryOutputStream"><type>GMemoryOutputStream</type></link>
195
</simpara></listitem></varlistentry>
196
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the number of bytes allocated for the data buffer
197
</simpara></listitem></varlistentry>
198
</variablelist></refsect2>
199
<refsect2 id="g-memory-output-stream-get-data-size" role="function" condition="since:2.18">
200
<title>g_memory_output_stream_get_data_size ()</title>
201
<indexterm zone="g-memory-output-stream-get-data-size" role="2.18"><primary sortas="memory_output_stream_get_data_size">g_memory_output_stream_get_data_size</primary></indexterm><programlisting><link linkend="gsize">gsize</link> g_memory_output_stream_get_data_size
202
(<link linkend="GMemoryOutputStream">GMemoryOutputStream</link> *ostream);</programlisting>
204
Returns the number of bytes from the start up
205
to including the last byte written in the stream
206
that has not been truncated away.</para>
208
</para><variablelist role="params">
209
<varlistentry><term><parameter>ostream</parameter> :</term>
210
<listitem><simpara> a <link linkend="GMemoryOutputStream"><type>GMemoryOutputStream</type></link>
211
</simpara></listitem></varlistentry>
212
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the number of bytes written to the stream
214
</simpara></listitem></varlistentry>
215
</variablelist><para role="since">Since 2.18</para></refsect2>
218
<refsect1 id="GMemoryOutputStream.property-details" role="property_details">
219
<title role="property_details.title">Property Details</title>
220
<refsect2 id="GMemoryOutputStream--data" role="property"><title>The <literal>"data"</literal> property</title>
221
<indexterm zone="GMemoryOutputStream--data" role="2.24"><primary sortas="MemoryOutputStream:data">GMemoryOutputStream:data</primary></indexterm><programlisting> "data" <link linkend="gpointer">gpointer</link> : Read / Write / Construct Only</programlisting>
223
Pointer to buffer where data will be written.</para>
225
</para><para>Since 2.24</para>
227
<refsect2 id="GMemoryOutputStream--data-size" role="property"><title>The <literal>"data-size"</literal> property</title>
228
<indexterm zone="GMemoryOutputStream--data-size" role="2.24"><primary sortas="MemoryOutputStream:data-size">GMemoryOutputStream:data-size</primary></indexterm><programlisting> "data-size" <link linkend="gulong">gulong</link> : Read</programlisting>
230
Size of data written to the buffer.</para>
232
</para><para>Since 2.24</para>
234
<refsect2 id="GMemoryOutputStream--destroy-function" role="property"><title>The <literal>"destroy-function"</literal> property</title>
235
<indexterm zone="GMemoryOutputStream--destroy-function" role="2.24"><primary sortas="MemoryOutputStream:destroy-function">GMemoryOutputStream:destroy-function</primary></indexterm><programlisting> "destroy-function" <link linkend="gpointer">gpointer</link> : Read / Write / Construct Only</programlisting>
237
Function called with the buffer as argument when the stream is destroyed.</para>
239
</para><para>Since 2.24</para>
241
<refsect2 id="GMemoryOutputStream--realloc-function" role="property"><title>The <literal>"realloc-function"</literal> property</title>
242
<indexterm zone="GMemoryOutputStream--realloc-function" role="2.24"><primary sortas="MemoryOutputStream:realloc-function">GMemoryOutputStream:realloc-function</primary></indexterm><programlisting> "realloc-function" <link linkend="gpointer">gpointer</link> : Read / Write / Construct Only</programlisting>
244
Function with realloc semantics called to enlarge the buffer.</para>
246
</para><para>Since 2.24</para>
248
<refsect2 id="GMemoryOutputStream--size" role="property"><title>The <literal>"size"</literal> property</title>
249
<indexterm zone="GMemoryOutputStream--size" role="2.24"><primary sortas="MemoryOutputStream:size">GMemoryOutputStream:size</primary></indexterm><programlisting> "size" <link linkend="gulong">gulong</link> : Read / Write / Construct Only</programlisting>
251
Current size of the data buffer.</para>
253
</para><para>Since 2.24</para>
259
<refsect1 id="GMemoryOutputStream.see-also">
260
<title>See Also</title>