Fix the wrong-category schema test
[glib.git] / glib / gbuffer.h
blob6bb29b73c8e979d3366b1f7eacc84edadef7c6cd
1 /*
2 * Copyright © 2009, 2010 Codethink Limited
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Author: Ryan Lortie <desrt@desrt.ca>
22 #ifndef __G_BUFFER_H__
23 #define __G_BUFFER_H__
25 #include <glib/gtypes.h>
27 /* < private >
28 * GBuffer:
29 * @data: a pointer to the data held in the buffer
30 * @size: the size of @data
32 * A simple refcounted data type representing a byte sequence from an
33 * unspecified origin.
35 * The purpose of a #GBuffer is to keep the memory region that it holds
36 * alive for as long as anyone holds a reference to the buffer. When
37 * the last reference count is dropped, the memory is released.
39 * A #GBuffer can come from many different origins that may have
40 * different procedures for freeing the memory region. Examples are
41 * memory from g_malloc(), from memory slices, from a #GMappedFile or
42 * memory from other allocators.
44 typedef struct _GBuffer GBuffer;
46 /* < private >
47 * GBufferFreeFunc:
48 * @buffer: the #GBuffer to be freed
50 * This function is provided by creators of a #GBuffer. It is the
51 * function to be called when the reference count of @buffer drops to
52 * zero. It should free any memory associated with the buffer and free
53 * @buffer itself.
55 typedef void (* GBufferFreeFunc) (GBuffer *buffer);
57 struct _GBuffer
59 gconstpointer data;
60 gsize size;
62 /*< protected >*/
63 GBufferFreeFunc free_func;
65 /*< private >*/
66 gint ref_count;
69 G_GNUC_INTERNAL
70 GBuffer * g_buffer_new_from_data (gconstpointer data,
71 gsize size);
72 G_GNUC_INTERNAL
73 GBuffer * g_buffer_new_take_data (gpointer data,
74 gsize size);
75 G_GNUC_INTERNAL
76 GBuffer * g_buffer_new_from_static_data (gconstpointer data,
77 gsize size);
78 G_GNUC_INTERNAL
79 GBuffer * g_buffer_new_from_pointer (gconstpointer data,
80 gsize size,
81 GDestroyNotify notify,
82 gpointer user_data);
83 G_GNUC_INTERNAL
84 GBuffer * g_buffer_ref (GBuffer *buffer);
85 G_GNUC_INTERNAL
86 void g_buffer_unref (GBuffer *buffer);
88 #endif /* __G_BUFFER_H__ */