alternative to assert
[gtkD.git] / src / glib / MemoryChunk.d
blob58ca3115cee5d19138ddefd4ee64ea0d089f2d35
1 /*
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
26 * outPack = glib
27 * outFile = MemoryChunk
28 * strct = GMemChunk
29 * realStrct=
30 * ctorStrct=
31 * clss = MemoryChunk
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_mem_chunk_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Str
45 * structWrap:
46 * local aliases:
49 module glib.MemoryChunk;
51 private import glib.glibtypes;
53 private import lib.glib;
55 private import glib.Str;
57 /**
58 * Description
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
64 * slice allocator,
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;
88 * gchar *mem[10000];
89 * gint i;
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++)
96 * {
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++)
100 * mem[i][j] = i * 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;
112 * GRealArray *array;
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;
121 * array->len = 0;
122 * array->alloc = 0;
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()
140 return gMemChunk;
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;
165 * Warning
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
167 * instead
168 * Creates a new GMemChunk.
169 * name:
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.
173 * atom_size:
174 * the size, in bytes, of each element in the GMemChunk.
175 * area_size:
176 * the size, in bytes, of each block of memory allocated to contain
177 * the atoms.
178 * type:
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.
184 * Returns:
185 * the new GMemChunk.
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) );
194 * Warning
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.
197 * mem_chunk:
198 * a GMemChunk.
199 * Returns:
200 * a pointer to the allocated atom.
202 public void* alloc()
204 // gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
205 return g_mem_chunk_alloc(gMemChunk);
209 * Warning
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.
212 * mem_chunk:
213 * a GMemChunk.
214 * Returns:
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);
224 * Warning
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.
229 * mem_chunk:
230 * a GMemChunk.
231 * mem:
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);
241 * Warning
242 * g_mem_chunk_destroy has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
243 * allocator instead
244 * Frees all of the memory allocated for a GMemChunk.
245 * mem_chunk:
246 * a GMemChunk.
248 public void destroy()
250 // void g_mem_chunk_destroy (GMemChunk *mem_chunk);
251 g_mem_chunk_destroy(gMemChunk);
259 * Warning
260 * g_mem_chunk_reset has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
261 * allocator instead
262 * Resets a GMemChunk to its initial state.
263 * It frees all of the currently allocated blocks of memory.
264 * mem_chunk:
265 * a GMemChunk.
267 public void reset()
269 // void g_mem_chunk_reset (GMemChunk *mem_chunk);
270 g_mem_chunk_reset(gMemChunk);
274 * Warning
275 * g_mem_chunk_clean has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
276 * allocator instead
277 * Frees any blocks in a GMemChunk which are no longer being used.
278 * mem_chunk:
279 * a GMemChunk.
281 public void clean()
283 // void g_mem_chunk_clean (GMemChunk *mem_chunk);
284 g_mem_chunk_clean(gMemChunk);
288 * Warning
289 * g_blow_chunks has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
290 * allocator instead
291 * Calls g_mem_chunk_clean() on all GMemChunk objects.
293 public static void gBlowChunks()
295 // void g_blow_chunks (void);
296 g_blow_chunks();
300 * Warning
301 * g_mem_chunk_info has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
302 * allocator instead
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);
310 g_mem_chunk_info();
314 * Warning
315 * g_mem_chunk_print has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
316 * allocator instead
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.
320 * mem_chunk:
321 * a GMemChunk.
323 public void print()
325 // void g_mem_chunk_print (GMemChunk *mem_chunk);
326 g_mem_chunk_print(gMemChunk);