2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit 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
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Memory-Chunks.html
27 * outFile = MemoryChunk
49 module glib
.MemoryChunk
;
51 private import glib
.glibtypes
;
53 private import lib
.glib
;
55 private import glib
.Str
;
59 * Memory chunks provide an space-efficient way to allocate equal-sized
60 * pieces of memory, called atoms. However, due to the administrative
61 * overhead (in particular for G_ALLOC_AND_FREE, and when used from multiple
62 * threads), they are in practise often slower than direct use of g_malloc().
63 * Therefore, memory chunks have been deprecated in favor of the
65 * which has been added in 2.10. All internal uses of memory chunks in
66 * GLib have been converted to the g_slice API.
67 * There are two types of memory chunks, G_ALLOC_ONLY, and G_ALLOC_AND_FREE.
68 * G_ALLOC_ONLY chunks only allow allocation of atoms. The atoms can never
69 * be freed individually. The memory chunk can only be free in its entirety.
70 * G_ALLOC_AND_FREE chunks do allow atoms to be freed individually.
71 * The disadvantage of this is that the memory chunk has to keep track of which
72 * atoms have been freed. This results in more memory being used and a slight
73 * degradation in performance.
74 * To create a memory chunk use g_mem_chunk_new() or the convenience macro
75 * g_mem_chunk_create().
76 * To allocate a new atom use g_mem_chunk_alloc(), g_mem_chunk_alloc0(),
77 * or the convenience macros g_chunk_new() or g_chunk_new0().
78 * To free an atom use g_mem_chunk_free(), or the convenience macro
79 * g_chunk_free(). (Atoms can only be freed if the memory chunk is created
80 * with the type set to G_ALLOC_AND_FREE.)
81 * To free any blocks of memory which are no longer being used, use
82 * g_mem_chunk_clean(). To clean all memory chunks, use g_blow_chunks().
83 * To reset the memory chunk, freeing all of the atoms, use g_mem_chunk_reset().
84 * To destroy a memory chunk, use g_mem_chunk_destroy().
85 * To help debug memory chunks, use g_mem_chunk_info() and g_mem_chunk_print().
86 * Example3.Using a GMemChunk
87 * GMemChunk *mem_chunk;
90 * /+* Create a GMemChunk with atoms 50 bytes long, and memory blocks holding
91 * 100 bytes. Note that this means that only 2 atoms fit into each memory
92 * block and so isn't very efficient. +/
93 * mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
94 * /+* Now allocate 10000 atoms. +/
95 * for (i = 0; i < 10000; i++)
97 * mem[i] = g_chunk_new (gchar, mem_chunk);
98 * /+* Fill in the atom memory with some junk. +/
99 * for (j = 0; j < 50; j++)
102 * /+* Now free all of the atoms. Note that since we are going to destroy the
103 * GMemChunk, this wouldn't normally be used. +/
104 * for (i = 0; i < 10000; i++)
106 * g_mem_chunk_free (mem_chunk, mem[i]);
108 * /+* We are finished with the GMemChunk, so we destroy it. +/
109 * g_mem_chunk_destroy (mem_chunk);
110 * Example4.Using a GMemChunk with data structures
111 * GMemChunk *array_mem_chunk;
113 * /+* Create a GMemChunk to hold GRealArray structures, using the
114 * g_mem_chunk_create() convenience macro. We want 1024 atoms in each
115 * memory block, and we want to be able to free individual atoms. +/
116 * array_mem_chunk = g_mem_chunk_create (GRealArray, 1024, G_ALLOC_AND_FREE);
117 * /+* Allocate one atom, using the g_chunk_new() convenience macro. +/
118 * array = g_chunk_new (GRealArray, array_mem_chunk);
119 * /+* We can now use array just like a normal pointer to a structure. +/
120 * array->data = NULL;
123 * array->zero_terminated = (zero_terminated ? 1 : 0);
124 * array->clear = (clear ? 1 : 0);
125 * array->elt_size = elt_size;
126 * /+* We can free the element, so it can be reused. +/
127 * g_chunk_free (array, array_mem_chunk);
128 * /+* We destroy the GMemChunk when we are finished with it. +/
129 * g_mem_chunk_destroy (array_mem_chunk);
131 public class MemoryChunk
134 /** the main Gtk struct */
135 protected GMemChunk
* gMemChunk
;
138 public GMemChunk
* getMemoryChunkStruct()
144 /** the main Gtk struct as a void* */
145 protected void* getStruct()
147 return cast(void*)gMemChunk
;
151 * Sets our main struct and passes it to the parent class
153 public this (GMemChunk
* gMemChunk
)
155 this.gMemChunk
= gMemChunk
;
166 * g_mem_chunk_new has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice allocator
168 * Creates a new GMemChunk.
170 * a string to identify the GMemChunk. It is not copied so it
171 * should be valid for the lifetime of the GMemChunk. It is only used in
172 * g_mem_chunk_print(), which is used for debugging.
174 * the size, in bytes, of each element in the GMemChunk.
176 * the size, in bytes, of each block of memory allocated to contain
179 * the type of the GMemChunk.
180 * G_ALLOC_AND_FREE is used if the atoms will be freed individually.
181 * G_ALLOC_ONLY should be used if atoms will never be freed individually.
182 * G_ALLOC_ONLY is quicker, since it does not need to track free atoms,
183 * but it obviously wastes memory if you no longer need many of the atoms.
187 public this (char[] name
, int atomSize
, uint areaSize
, int type
)
189 // GMemChunk* g_mem_chunk_new (const gchar *name, gint atom_size, gulong area_size, gint type);
190 this(cast(GMemChunk
*)g_mem_chunk_new(Str
.toStringz(name
), atomSize
, areaSize
, type
) );
195 * g_mem_chunk_alloc has been deprecated since version 2.10 and should not be used in newly-written code. Use g_slice_alloc() instead
196 * Allocates an atom of memory from a GMemChunk.
200 * a pointer to the allocated atom.
204 // gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
205 return g_mem_chunk_alloc(gMemChunk
);
210 * g_mem_chunk_alloc0 has been deprecated since version 2.10 and should not be used in newly-written code. Use g_slice_alloc0() instead
211 * Allocates an atom of memory from a GMemChunk, setting the memory to 0.
215 * a pointer to the allocated atom.
217 public void* alloc0()
219 // gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
220 return g_mem_chunk_alloc0(gMemChunk
);
225 * g_mem_chunk_free has been deprecated since version 2.10 and should not be used in newly-written code. Use g_slice_free1() instead
226 * Frees an atom in a GMemChunk.
227 * This should only be called if the GMemChunk was created with
228 * G_ALLOC_AND_FREE. Otherwise it will simply return.
232 * a pointer to the atom to free.
234 public void free(void* mem
)
236 // void g_mem_chunk_free (GMemChunk *mem_chunk, gpointer mem);
237 g_mem_chunk_free(gMemChunk
, mem
);
242 * g_mem_chunk_destroy has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
244 * Frees all of the memory allocated for a GMemChunk.
248 public void destroy()
250 // void g_mem_chunk_destroy (GMemChunk *mem_chunk);
251 g_mem_chunk_destroy(gMemChunk
);
260 * g_mem_chunk_reset has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
262 * Resets a GMemChunk to its initial state.
263 * It frees all of the currently allocated blocks of memory.
269 // void g_mem_chunk_reset (GMemChunk *mem_chunk);
270 g_mem_chunk_reset(gMemChunk
);
275 * g_mem_chunk_clean has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
277 * Frees any blocks in a GMemChunk which are no longer being used.
283 // void g_mem_chunk_clean (GMemChunk *mem_chunk);
284 g_mem_chunk_clean(gMemChunk
);
289 * g_blow_chunks has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
291 * Calls g_mem_chunk_clean() on all GMemChunk objects.
293 public static void gBlowChunks()
295 // void g_blow_chunks (void);
301 * g_mem_chunk_info has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
303 * Outputs debugging information for all GMemChunk objects currently in use.
304 * It outputs the number of GMemChunk objects currently allocated,
305 * and calls g_mem_chunk_print() to output information on each one.
307 public static void info()
309 // void g_mem_chunk_info (void);
315 * g_mem_chunk_print has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
317 * Outputs debugging information for a GMemChunk.
318 * It outputs the name of the GMemChunk (set with g_mem_chunk_new()),
319 * the number of bytes used, and the number of blocks of memory allocated.
325 // void g_mem_chunk_print (GMemChunk *mem_chunk);
326 g_mem_chunk_print(gMemChunk
);