2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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
50 module glib
.MemoryChunk
;
56 import tango
.io
.Stdout
; // use the tango loging?
60 private import gtkc
.glibtypes
;
62 private import gtkc
.glib
;
65 private import glib
.Str
;
72 * Memory chunks provide an space-efficient way to allocate equal-sized
73 * pieces of memory, called atoms. However, due to the administrative
74 * overhead (in particular for G_ALLOC_AND_FREE, and when used from multiple
75 * threads), they are in practise often slower than direct use of g_malloc().
76 * Therefore, memory chunks have been deprecated in favor of the
78 * which has been added in 2.10. All internal uses of memory chunks in
79 * GLib have been converted to the g_slice API.
80 * There are two types of memory chunks, G_ALLOC_ONLY, and G_ALLOC_AND_FREE.
81 * G_ALLOC_ONLY chunks only allow allocation of atoms. The atoms can never
82 * be freed individually. The memory chunk can only be free in its entirety.
83 * G_ALLOC_AND_FREE chunks do allow atoms to be freed individually.
84 * The disadvantage of this is that the memory chunk has to keep track of which
85 * atoms have been freed. This results in more memory being used and a slight
86 * degradation in performance.
87 * To create a memory chunk use g_mem_chunk_new() or the convenience macro
88 * g_mem_chunk_create().
89 * To allocate a new atom use g_mem_chunk_alloc(), g_mem_chunk_alloc0(),
90 * or the convenience macros g_chunk_new() or g_chunk_new0().
91 * To free an atom use g_mem_chunk_free(), or the convenience macro
92 * g_chunk_free(). (Atoms can only be freed if the memory chunk is created
93 * with the type set to G_ALLOC_AND_FREE.)
94 * To free any blocks of memory which are no longer being used, use
95 * g_mem_chunk_clean(). To clean all memory chunks, use g_blow_chunks().
96 * To reset the memory chunk, freeing all of the atoms, use g_mem_chunk_reset().
97 * To destroy a memory chunk, use g_mem_chunk_destroy().
98 * To help debug memory chunks, use g_mem_chunk_info() and g_mem_chunk_print().
99 * Example3.Using a GMemChunk
100 * GMemChunk *mem_chunk;
103 * /+* Create a GMemChunk with atoms 50 bytes long, and memory blocks holding
104 * 100 bytes. Note that this means that only 2 atoms fit into each memory
105 * block and so isn't very efficient. +/
106 * mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);
107 * /+* Now allocate 10000 atoms. +/
108 * for (i = 0; i < 10000; i++)
110 * mem[i] = g_chunk_new (gchar, mem_chunk);
111 * /+* Fill in the atom memory with some junk. +/
112 * for (j = 0; j < 50; j++)
115 * /+* Now free all of the atoms. Note that since we are going to destroy the
116 * GMemChunk, this wouldn't normally be used. +/
117 * for (i = 0; i < 10000; i++)
119 * g_mem_chunk_free (mem_chunk, mem[i]);
121 * /+* We are finished with the GMemChunk, so we destroy it. +/
122 * g_mem_chunk_destroy (mem_chunk);
123 * Example4.Using a GMemChunk with data structures
124 * GMemChunk *array_mem_chunk;
126 * /+* Create a GMemChunk to hold GRealArray structures, using the
127 * g_mem_chunk_create() convenience macro. We want 1024 atoms in each
128 * memory block, and we want to be able to free individual atoms. +/
129 * array_mem_chunk = g_mem_chunk_create (GRealArray, 1024, G_ALLOC_AND_FREE);
130 * /+* Allocate one atom, using the g_chunk_new() convenience macro. +/
131 * array = g_chunk_new (GRealArray, array_mem_chunk);
132 * /+* We can now use array just like a normal pointer to a structure. +/
133 * array->data = NULL;
136 * array->zero_terminated = (zero_terminated ? 1 : 0);
137 * array->clear = (clear ? 1 : 0);
138 * array->elt_size = elt_size;
139 * /+* We can free the element, so it can be reused. +/
140 * g_chunk_free (array, array_mem_chunk);
141 * /+* We destroy the GMemChunk when we are finished with it. +/
142 * g_mem_chunk_destroy (array_mem_chunk);
144 public class MemoryChunk
147 /** the main Gtk struct */
148 protected GMemChunk
* gMemChunk
;
151 public GMemChunk
* getMemoryChunkStruct()
157 /** the main Gtk struct as a void* */
158 protected void* getStruct()
160 return cast(void*)gMemChunk
;
164 * Sets our main struct and passes it to the parent class
166 public this (GMemChunk
* gMemChunk
)
170 if ( gMemChunk
is null )
175 Stdout("struct gMemChunk is null on constructor").newline
;
179 printf("struct gMemChunk is null on constructor");
186 assert(gMemChunk
!is null, "struct gMemChunk is null on constructor");
188 this.gMemChunk
= gMemChunk
;
199 * g_mem_chunk_new has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice allocator
201 * Creates a new GMemChunk.
203 * a string to identify the GMemChunk. It is not copied so it
204 * should be valid for the lifetime of the GMemChunk. It is only used in
205 * g_mem_chunk_print(), which is used for debugging.
207 * the size, in bytes, of each element in the GMemChunk.
209 * the size, in bytes, of each block of memory allocated to contain
212 * the type of the GMemChunk.
213 * G_ALLOC_AND_FREE is used if the atoms will be freed individually.
214 * G_ALLOC_ONLY should be used if atoms will never be freed individually.
215 * G_ALLOC_ONLY is quicker, since it does not need to track free atoms,
216 * but it obviously wastes memory if you no longer need many of the atoms.
220 public this (char[] name
, int atomSize
, uint areaSize
, int type
)
222 // GMemChunk* g_mem_chunk_new (const gchar *name, gint atom_size, gulong area_size, gint type);
223 this(cast(GMemChunk
*)g_mem_chunk_new(Str
.toStringz(name
), atomSize
, areaSize
, type
) );
228 * 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
229 * Allocates an atom of memory from a GMemChunk.
233 * a pointer to the allocated atom.
237 // gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
238 return g_mem_chunk_alloc(gMemChunk
);
243 * 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
244 * Allocates an atom of memory from a GMemChunk, setting the memory to 0.
248 * a pointer to the allocated atom.
250 public void* alloc0()
252 // gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
253 return g_mem_chunk_alloc0(gMemChunk
);
258 * 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
259 * Frees an atom in a GMemChunk.
260 * This should only be called if the GMemChunk was created with
261 * G_ALLOC_AND_FREE. Otherwise it will simply return.
265 * a pointer to the atom to free.
267 public void free(void* mem
)
269 // void g_mem_chunk_free (GMemChunk *mem_chunk, gpointer mem);
270 g_mem_chunk_free(gMemChunk
, mem
);
275 * g_mem_chunk_destroy has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
277 * Frees all of the memory allocated for a GMemChunk.
281 public void destroy()
283 // void g_mem_chunk_destroy (GMemChunk *mem_chunk);
284 g_mem_chunk_destroy(gMemChunk
);
293 * g_mem_chunk_reset has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
295 * Resets a GMemChunk to its initial state.
296 * It frees all of the currently allocated blocks of memory.
302 // void g_mem_chunk_reset (GMemChunk *mem_chunk);
303 g_mem_chunk_reset(gMemChunk
);
308 * g_mem_chunk_clean has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
310 * Frees any blocks in a GMemChunk which are no longer being used.
316 // void g_mem_chunk_clean (GMemChunk *mem_chunk);
317 g_mem_chunk_clean(gMemChunk
);
322 * g_blow_chunks has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
324 * Calls g_mem_chunk_clean() on all GMemChunk objects.
326 public static void gBlowChunks()
328 // void g_blow_chunks (void);
334 * g_mem_chunk_info has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
336 * Outputs debugging information for all GMemChunk objects currently in use.
337 * It outputs the number of GMemChunk objects currently allocated,
338 * and calls g_mem_chunk_print() to output information on each one.
340 public static void info()
342 // void g_mem_chunk_info (void);
348 * g_mem_chunk_print has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
350 * Outputs debugging information for a GMemChunk.
351 * It outputs the name of the GMemChunk (set with g_mem_chunk_new()),
352 * the number of bytes used, and the number of blocks of memory allocated.
358 // void g_mem_chunk_print (GMemChunk *mem_chunk);
359 g_mem_chunk_print(gMemChunk
);