GIO Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces |
#include <gio/gio.h> gpointer (*GReallocFunc) (gpointer data, gsize size); GMemoryOutputStream; GOutputStream * g_memory_output_stream_new (gpointer data, gsize len, GReallocFunc realloc_fn, GDestroyNotify destroy); gpointer g_memory_output_stream_get_data (GMemoryOutputStream *ostream); gsize g_memory_output_stream_get_size (GMemoryOutputStream *ostream); gsize g_memory_output_stream_get_data_size (GMemoryOutputStream *ostream);
GMemoryOutputStream is a class for using arbitrary memory chunks as output for GIO streaming output operations.
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()
.
|
memory block to reallocate |
|
size to reallocate data to
|
Returns : |
a pointer to the reallocated memory |
typedef struct _GMemoryOutputStream GMemoryOutputStream;
Implements GOutputStream for arbitrary memory chunks.
GOutputStream * g_memory_output_stream_new (gpointer data, gsize len, GReallocFunc realloc_fn, GDestroyNotify destroy);
Creates a new GMemoryOutputStream.
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. To construct a fixed-size output stream,
pass NULL
as realloc_fn
.
/* a stream that can grow */ stream = g_memory_output_stream_new (NULL, 0, realloc, free); /* a fixed-size stream */ data = malloc (200); stream2 = g_memory_output_stream_new (data, 200, NULL, free);
|
pointer to a chunk of memory to use, or NULL
|
|
the size of data
|
|
a function with realloc() semantics to be called when
data needs to be grown, or NULL
|
|
a function to be called on data when the stream is finalized,
or NULL
|
Returns : |
A newly created GMemoryOutputStream object. |
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.
|
a GMemoryOutputStream |
Returns : |
pointer to the stream's data |
gsize g_memory_output_stream_get_size (GMemoryOutputStream *ostream);
Gets the size of the currently allocated data area (availible from
g_memory_output_stream_get_data()
). If the stream isn't
growable (no realloc was passed to g_memory_output_stream_new()
) then
this is the maximum size of the stream and further writes
will return G_IO_ERROR_NO_SPACE
.
Note that for growable streams the returned size may become invalid on the next write or truncate operation on the stream.
If you want the number of bytes currently written to the stream, use
g_memory_output_stream_get_data_size()
.
|
a GMemoryOutputStream |
Returns : |
the number of bytes allocated for the data buffer |
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.
|
a GMemoryOutputStream |
Returns : |
the number of bytes written to the stream |
Since 2.18