Functions
GReallocFunc ()
gpointer
(*GReallocFunc) (gpointer data,
gsize size);
Changes the size of the memory block pointed to by data
to
size
bytes.
The function should have the same semantics as realloc().
Returns
a pointer to the reallocated memory
g_memory_output_stream_new ()
GOutputStream *
g_memory_output_stream_new (gpointer data,
gsize size,
GReallocFunc realloc_function,
GDestroyNotify destroy_function);
Creates a new GMemoryOutputStream.
In most cases this is not the function you want. See
g_memory_output_stream_new_resizable() instead.
If data
is non-NULL, the stream will use that for its internal storage.
If realloc_fn
is non-NULL, it will be used for resizing the internal
storage when necessary and the stream will be considered resizable.
In that case, the stream will start out being (conceptually) empty.
size
is used only as a hint for how big data
is. Specifically,
seeking to the end of a newly-created stream will seek to zero, not
size
. Seeking past the end of the stream and then writing will
introduce a zero-filled gap.
If realloc_fn
is NULL then the stream is fixed-sized. Seeking to
the end will seek to size
exactly. Writing past the end will give
an 'out of space' error. Attempting to seek past the end will fail.
Unlike the resizable case, seeking to an offset within the stream and
writing will preserve the bytes passed in as data
before that point
and will return them as part of g_memory_output_stream_steal_data().
If you intend to seek you should probably therefore ensure that data
is properly initialised.
It is probably only meaningful to provide data
and size
in the case
that you want a fixed-sized stream. Put another way: if realloc_fn
is non-NULL then it makes most sense to give data
as NULL and
size
as 0 (allowing GMemoryOutputStream to do the initial
allocation for itself).
[skip]
g_memory_output_stream_new_resizable ()
GOutputStream *
g_memory_output_stream_new_resizable (void);
Creates a new GMemoryOutputStream, using g_realloc() and g_free()
for memory allocation.
Since: 2.36
g_memory_output_stream_get_data ()
gpointer
g_memory_output_stream_get_data (GMemoryOutputStream *ostream);
Gets any loaded data from the ostream
.
Note that the returned pointer may become invalid on the next
write or truncate operation on the stream.
Returns
pointer to the stream's data, or NULL if the data
has been stolen.
[transfer none]
g_memory_output_stream_get_data_size ()
gsize
g_memory_output_stream_get_data_size (GMemoryOutputStream *ostream);
Returns the number of bytes from the start up to including the last
byte written in the stream that has not been truncated away.
Returns
the number of bytes written to the stream
Since: 2.18
g_memory_output_stream_steal_data ()
gpointer
g_memory_output_stream_steal_data (GMemoryOutputStream *ostream);
Gets any loaded data from the ostream
. Ownership of the data
is transferred to the caller; when no longer needed it must be
freed using the free function set in ostream
's
“destroy-function” property.
ostream
must be closed before calling this function.
Returns
the stream's data, or NULL if it has previously
been stolen.
[transfer full]
Since: 2.26
g_memory_output_stream_steal_as_bytes ()
GBytes *
g_memory_output_stream_steal_as_bytes (GMemoryOutputStream *ostream);
Returns data from the ostream
as a GBytes. ostream
must be
closed before calling this function.
Returns
the stream's data.
[transfer full]
Since: 2.34
Property Details
The “data” property
“data” gpointer
Pointer to buffer where data will be written.
Owner: GMemoryOutputStream
Flags: Read / Write / Construct Only
Since: 2.24
The “data-size” property
“data-size” gulong
Size of data written to the buffer.
Owner: GMemoryOutputStream
Flags: Read
Since: 2.24
The “destroy-function” property
“destroy-function” gpointer
Function called with the buffer as argument when the stream is destroyed.
[skip]
Owner: GMemoryOutputStream
Flags: Read / Write / Construct Only
Since: 2.24
The “realloc-function” property
“realloc-function” gpointer
Function with realloc semantics called to enlarge the buffer.
[skip]
Owner: GMemoryOutputStream
Flags: Read / Write / Construct Only
Since: 2.24
The “size” property
“size” gulong
Current size of the data buffer.
Owner: GMemoryOutputStream
Flags: Read / Write / Construct Only
Since: 2.24