Object Hierarchy:

GLib.MemoryOutputStream GLib.MemoryOutputStream GLib.MemoryOutputStream GLib.OutputStream GLib.OutputStream GLib.OutputStream->GLib.MemoryOutputStream GLib.Object GLib.Object GLib.Object->GLib.OutputStream GLib.PollableOutputStream GLib.PollableOutputStream GLib.PollableOutputStream->GLib.MemoryOutputStream GLib.Seekable GLib.Seekable GLib.Seekable->GLib.MemoryOutputStream


[ CCode ( type_id = "g_memory_output_stream_get_type ()" ) ]
public class MemoryOutputStream : OutputStream, PollableOutputStream, Seekable

`GMemoryOutputStream` is a class for using arbitrary memory chunks as output for GIO streaming output operations.

As of GLib 2.34, `GMemoryOutputStream` trivially implements [iface@Gio.PollableOutputStream]: it always polls as ready.

Example: MemoryOutputStream:

public static int main (string[] args) {
try {
MemoryOutputStream os = new MemoryOutputStream (null, GLib.realloc,;

// Write data to memory:
DataOutputStream dos = new DataOutputStream (os);
dos.put_int16 (int16.MIN);
dos.put_int32 (int32.MIN);
dos.put_int64 (int64.MIN);
dos.close ();

// Read data:
uint8[] data = os.steal_data ();
data.length = (int) os.get_data_size ();

MemoryInputStream @is = new MemoryInputStream.from_data (data,;
DataInputStream dis = new DataInputStream (@is);
print ("%d (Expected: %d)\n", dis.read_int16 (), int16.MIN);
print ("%d (Expected: %d)\n", dis.read_int32 (), int32.MIN);
print ("%"+int64.FORMAT+" (Expected: %"+int64.FORMAT+")\n", dis.read_int64 (), int64.MIN);
} catch (IOError e) {
print ("IOError %s\n", e.message);
return 0;

valac --pkg gio-2.0 GLib.MemoryOutputStream.vala

Namespace: GLib
Package: gio-2.0



Static methods:

Creation methods:


Inherited Members:

All known members inherited from interface GLib.PollableOutputStream
All known members inherited from interface GLib.Seekable