Blame docs/reference/gio/html/GMemoryOutputStream.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>GMemoryOutputStream: GIO Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GIO Reference Manual">
Packit ae235b
<link rel="up" href="streaming.html" title="Streaming I/O">
Packit ae235b
<link rel="prev" href="GMemoryInputStream.html" title="GMemoryInputStream">
Packit ae235b
<link rel="next" href="GBufferedInputStream.html" title="GBufferedInputStream">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Top  | 
Packit ae235b
                  Description  | 
Packit ae235b
                  Object Hierarchy  | 
Packit ae235b
                  Implemented Interfaces  | 
Packit ae235b
                  Properties
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

GMemoryOutputStream

Packit ae235b

GMemoryOutputStream — Streaming output operations on memory chunks

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
(*GReallocFunc) ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GOutputStream *
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_new ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GOutputStream *
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_new_resizable ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_get_data ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gsize
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_get_size ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gsize
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_get_data_size ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_steal_data ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
GBytes *
Packit ae235b
Packit ae235b
Packit ae235b
g_memory_output_stream_steal_as_bytes ()
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Properties

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
data
Packit ae235b
Read / Write / Construct Only
Packit ae235b
Packit ae235b
Packit ae235b
gulong
Packit ae235b
data-size
Packit ae235b
Read
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
destroy-function
Packit ae235b
Read / Write / Construct Only
Packit ae235b
Packit ae235b
Packit ae235b
gpointer
Packit ae235b
realloc-function
Packit ae235b
Read / Write / Construct Only
Packit ae235b
Packit ae235b
Packit ae235b
gulong
Packit ae235b
size
Packit ae235b
Read / Write / Construct Only
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
 
Packit ae235b
GMemoryOutputStream
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Object Hierarchy

Packit ae235b
    GObject
Packit ae235b
    ╰── GOutputStream
Packit ae235b
        ╰── GMemoryOutputStream
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Implemented Interfaces

Packit ae235b

Packit ae235b
GMemoryOutputStream implements
Packit ae235b
 GSeekable and  GPollableOutputStream.

Packit ae235b
Packit ae235b
Packit ae235b

Includes

Packit ae235b
#include <gio/gio.h>
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Description

Packit ae235b

GMemoryOutputStream is a class for using arbitrary

Packit ae235b
memory chunks as output for GIO streaming output operations.

Packit ae235b

As of GLib 2.34, GMemoryOutputStream trivially implements

Packit ae235b
GPollableOutputStream: it always polls as ready.

Packit ae235b
Packit ae235b
Packit ae235b

Functions

Packit ae235b
Packit ae235b

GReallocFunc ()

Packit ae235b
gpointer
Packit ae235b
(*GReallocFunc) (gpointer data,
Packit ae235b
                 gsize size);
Packit ae235b

Changes the size of the memory block pointed to by data

Packit ae235b
 to
Packit ae235b
size
Packit ae235b
 bytes.

Packit ae235b

The function should have the same semantics as realloc().

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

memory block to reallocate

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

size

Packit ae235b

size to reallocate data

Packit ae235b
to

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

a pointer to the reallocated memory

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_new ()

Packit ae235b
GOutputStream *
Packit ae235b
g_memory_output_stream_new (gpointer data,
Packit ae235b
                            gsize size,
Packit ae235b
                            GReallocFunc realloc_function,
Packit ae235b
                            GDestroyNotify destroy_function);
Packit ae235b

Creates a new GMemoryOutputStream.

Packit ae235b

In most cases this is not the function you want. See

Packit ae235b
g_memory_output_stream_new_resizable() instead.

Packit ae235b

If data

Packit ae235b
 is non-NULL, the stream will use that for its internal storage.

Packit ae235b

If realloc_fn

Packit ae235b
 is non-NULL, it will be used for resizing the internal
Packit ae235b
storage when necessary and the stream will be considered resizable.
Packit ae235b
In that case, the stream will start out being (conceptually) empty.
Packit ae235b
size
Packit ae235b
 is used only as a hint for how big data
Packit ae235b
 is.  Specifically,
Packit ae235b
seeking to the end of a newly-created stream will seek to zero, not
Packit ae235b
size
Packit ae235b
.  Seeking past the end of the stream and then writing will
Packit ae235b
introduce a zero-filled gap.

Packit ae235b

If realloc_fn

Packit ae235b
 is NULL then the stream is fixed-sized.  Seeking to
Packit ae235b
the end will seek to size
Packit ae235b
 exactly.  Writing past the end will give
Packit ae235b
an 'out of space' error.  Attempting to seek past the end will fail.
Packit ae235b
Unlike the resizable case, seeking to an offset within the stream and
Packit ae235b
writing will preserve the bytes passed in as data
Packit ae235b
 before that point
Packit ae235b
and will return them as part of g_memory_output_stream_steal_data().
Packit ae235b
If you intend to seek you should probably therefore ensure that data
Packit ae235b
Packit ae235b
is properly initialised.

Packit ae235b

It is probably only meaningful to provide data

Packit ae235b
 and size
Packit ae235b
 in the case
Packit ae235b
that you want a fixed-sized stream.  Put another way: if realloc_fn
Packit ae235b
Packit ae235b
is non-NULL then it makes most sense to give data
Packit ae235b
 as NULL and
Packit ae235b
size
Packit ae235b
 as 0 (allowing GMemoryOutputStream to do the initial
Packit ae235b
allocation for itself).

Packit ae235b
Packit ae235b
  
Packit ae235b
    
Packit ae235b
      
Packit ae235b
        
1
Packit ae235b
2
Packit ae235b
3
Packit ae235b
4
Packit ae235b
5
Packit ae235b
6
Packit ae235b
7
Packit ae235b
8
Packit ae235b
9
Packit ae235b
        
// a stream that can grow
Packit ae235b
stream = g_memory_output_stream_new (NULL, 0, realloc, free);
Packit ae235b
Packit ae235b
// another stream that can grow
Packit ae235b
stream2 = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
Packit ae235b
Packit ae235b
// a fixed-size stream
Packit ae235b
data = malloc (200);
Packit ae235b
stream3 = g_memory_output_stream_new (data, 200, NULL, free);
Packit ae235b
      
Packit ae235b
    
Packit ae235b
  
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b

[skip]

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

data

Packit ae235b

pointer to a chunk of memory to use, or NULL.

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b

size

Packit ae235b

the size of data

Packit ae235b

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b

realloc_function

Packit ae235b

a function with realloc() semantics (like g_realloc())

Packit ae235b
to be called when data
Packit ae235b
needs to be grown, or NULL. 

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b

destroy_function

Packit ae235b

a function to be called on data

Packit ae235b
when the stream is
Packit ae235b
finalized, or NULL. 

Packit ae235b
[nullable]
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

A newly created GMemoryOutputStream object.

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_new_resizable ()

Packit ae235b
GOutputStream *
Packit ae235b
g_memory_output_stream_new_resizable (void);
Packit ae235b

Creates a new GMemoryOutputStream, using g_realloc() and g_free()

Packit ae235b
for memory allocation.

Packit ae235b

Since: 2.36

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_get_data ()

Packit ae235b
gpointer
Packit ae235b
g_memory_output_stream_get_data (GMemoryOutputStream *ostream);
Packit ae235b

Gets any loaded data from the ostream

Packit ae235b
.

Packit ae235b

Note that the returned pointer may become invalid on the next

Packit ae235b
write or truncate operation on the stream.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

ostream

Packit ae235b

a GMemoryOutputStream

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

pointer to the stream's data, or NULL if the data

Packit ae235b
has been stolen. 

Packit ae235b

[transfer none]

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_get_size ()

Packit ae235b
gsize
Packit ae235b
g_memory_output_stream_get_size (GMemoryOutputStream *ostream);
Packit ae235b

Gets the size of the currently allocated data area (available from

Packit ae235b
g_memory_output_stream_get_data()).

Packit ae235b

You probably don't want to use this function on resizable streams.

Packit ae235b
See g_memory_output_stream_get_data_size() instead.  For resizable
Packit ae235b
streams the size returned by this function is an implementation
Packit ae235b
detail and may be change at any time in response to operations on the
Packit ae235b
stream.

Packit ae235b

If the stream is fixed-sized (ie: no realloc was passed to

Packit ae235b
g_memory_output_stream_new()) then this is the maximum size of the
Packit ae235b
stream and further writes will return G_IO_ERROR_NO_SPACE.

Packit ae235b

In any case, if you want the number of bytes currently written to the

Packit ae235b
stream, use g_memory_output_stream_get_data_size().

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

ostream

Packit ae235b

a GMemoryOutputStream

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the number of bytes allocated for the data buffer

Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_get_data_size ()

Packit ae235b
gsize
Packit ae235b
g_memory_output_stream_get_data_size (GMemoryOutputStream *ostream);
Packit ae235b

Returns the number of bytes from the start up to including the last

Packit ae235b
byte written in the stream that has not been truncated away.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

ostream

Packit ae235b

a GMemoryOutputStream

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the number of bytes written to the stream

Packit ae235b
Packit ae235b

Since: 2.18

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_steal_data ()

Packit ae235b
gpointer
Packit ae235b
g_memory_output_stream_steal_data (GMemoryOutputStream *ostream);
Packit ae235b

Gets any loaded data from the ostream

Packit ae235b
. Ownership of the data
Packit ae235b
is transferred to the caller; when no longer needed it must be
Packit ae235b
freed using the free function set in ostream
Packit ae235b
's
Packit ae235b
“destroy-function” property.

Packit ae235b

ostream

Packit ae235b
 must be closed before calling this function.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

ostream

Packit ae235b

a GMemoryOutputStream

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the stream's data, or NULL if it has previously

Packit ae235b
been stolen. 

Packit ae235b

[transfer full]

Packit ae235b
Packit ae235b

Since: 2.26

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

g_memory_output_stream_steal_as_bytes ()

Packit ae235b
GBytes *
Packit ae235b
g_memory_output_stream_steal_as_bytes (GMemoryOutputStream *ostream);
Packit ae235b

Returns data from the ostream

Packit ae235b
 as a GBytes. ostream
Packit ae235b
 must be
Packit ae235b
closed before calling this function.

Packit ae235b
Packit ae235b

Parameters

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

ostream

Packit ae235b

a GMemoryOutputStream

Packit ae235b
 
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Returns

Packit ae235b

the stream's data.

Packit ae235b

[transfer full]

Packit ae235b
Packit ae235b

Since: 2.34

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Types and Values

Packit ae235b
Packit ae235b

GMemoryOutputStream

Packit ae235b
typedef struct _GMemoryOutputStream GMemoryOutputStream;
Packit ae235b

Implements GOutputStream for arbitrary memory chunks.

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Property Details

Packit ae235b
Packit ae235b

The “data” property

Packit ae235b
  “data”                     gpointer
Packit ae235b

Pointer to buffer where data will be written.

Packit ae235b

Flags: Read / Write / Construct Only

Packit ae235b

Since: 2.24

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

The “data-size” property

Packit ae235b
  “data-size”                gulong
Packit ae235b

Size of data written to the buffer.

Packit ae235b

Flags: Read

Packit ae235b

Since: 2.24

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

The “destroy-function” property

Packit ae235b
  “destroy-function”         gpointer
Packit ae235b

Function called with the buffer as argument when the stream is destroyed.

Packit ae235b

[skip]

Packit ae235b

Flags: Read / Write / Construct Only

Packit ae235b

Since: 2.24

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

The “realloc-function” property

Packit ae235b
  “realloc-function”         gpointer
Packit ae235b

Function with realloc semantics called to enlarge the buffer.

Packit ae235b

[skip]

Packit ae235b

Flags: Read / Write / Construct Only

Packit ae235b

Since: 2.24

Packit ae235b
Packit ae235b

Packit ae235b
Packit ae235b

The “size” property

Packit ae235b
  “size”                     gulong
Packit ae235b

Current size of the data buffer.

Packit ae235b

Flags: Read / Write / Construct Only

Packit ae235b

Since: 2.24

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

See Also

Packit ae235b

GMemoryInputStream

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Generated by GTK-Doc V1.27
Packit ae235b
</body>
Packit ae235b
</html>