1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Memory-Chunks.html
27  * outPack = glib
28  * outFile = MemoryChunk
29  * strct   = GMemChunk
30  * realStrct=
31  * ctorStrct=
32  * clss    = MemoryChunk
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_mem_chunk_
41  * 	- g_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- g_mem_chunk_print
46  * omit signals:
47  * imports:
48  * 	- glib.Str
49  * structWrap:
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.MemoryChunk;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 
63 private import glib.Str;
64 
65 
66 
67 
68 /**
69  * Description
70  * Memory chunks provide an space-efficient way to allocate equal-sized
71  * pieces of memory, called atoms. However, due to the administrative
72  * overhead (in particular for G_ALLOC_AND_FREE, and when used from
73  * multiple threads), they are in practise often slower than direct use
74  * of g_malloc(). Therefore, memory chunks have been deprecated in
75  * favor of the slice
76  * allocator, which has been added in 2.10. All internal uses of
77  * memory chunks in GLib have been converted to the
78  * g_slice API.
79  * There are two types of memory chunks, G_ALLOC_ONLY, and
80  * G_ALLOC_AND_FREE.
81  *  G_ALLOC_ONLY
82  * chunks only allow allocation of atoms. The atoms can never be freed
83  * individually. The memory chunk can only be free in its entirety.
84  *  G_ALLOC_AND_FREE chunks do
85  * allow atoms to be freed individually. The disadvantage of this is
86  * that the memory chunk has to keep track of which atoms have been
87  * freed. This results in more memory being used and a slight
88  * degradation in performance.
89  * To create a memory chunk use g_mem_chunk_new() or the convenience
90  * macro g_mem_chunk_create().
91  * To allocate a new atom use g_mem_chunk_alloc(),
92  * g_mem_chunk_alloc0(), or the convenience macros g_chunk_new() or
93  * g_chunk_new0().
94  * To free an atom use g_mem_chunk_free(), or the convenience macro
95  * g_chunk_free(). (Atoms can only be freed if the memory chunk is
96  * created with the type set to G_ALLOC_AND_FREE.)
97  * To free any blocks of memory which are no longer being used, use
98  * g_mem_chunk_clean(). To clean all memory chunks, use g_blow_chunks().
99  * To reset the memory chunk, freeing all of the atoms, use
100  * g_mem_chunk_reset().
101  * To destroy a memory chunk, use g_mem_chunk_destroy().
102  * To help debug memory chunks, use g_mem_chunk_info() and
103  * g_mem_chunk_print().
104  * $(DDOC_COMMENT example)
105  * $(DDOC_COMMENT example)
106  */
107 public class MemoryChunk
108 {
109 	
110 	/** the main Gtk struct */
111 	protected GMemChunk* gMemChunk;
112 	
113 	
114 	public GMemChunk* getMemoryChunkStruct()
115 	{
116 		return gMemChunk;
117 	}
118 	
119 	
120 	/** the main Gtk struct as a void* */
121 	protected void* getStruct()
122 	{
123 		return cast(void*)gMemChunk;
124 	}
125 	
126 	/**
127 	 * Sets our main struct and passes it to the parent class
128 	 */
129 	public this (GMemChunk* gMemChunk)
130 	{
131 		this.gMemChunk = gMemChunk;
132 	}
133 	
134 	/**
135 	 * Warning
136 	 * g_mem_chunk_print has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
137 	 *  allocator instead
138 	 * Outputs debugging information for a GMemChunk.
139 	 * It outputs the name of the GMemChunk (set with g_mem_chunk_new()),
140 	 * the number of bytes used, and the number of blocks of memory allocated.
141 	 */
142 	version(Tango)
143 	{
144 		public void print()
145 		{
146 			// void g_mem_chunk_print (GMemChunk *mem_chunk);
147 			g_mem_chunk_print(gMemChunk);
148 		}
149 	}
150 	else version(D_Version2)
151 	{
152 		public void print()
153 		{
154 			// void g_mem_chunk_print (GMemChunk *mem_chunk);
155 			g_mem_chunk_print(gMemChunk);
156 		}
157 	}
158 	else
159 	{
160 		public override void print()
161 		{
162 			// void g_mem_chunk_print (GMemChunk *mem_chunk);
163 			g_mem_chunk_print(gMemChunk);
164 		}
165 	}
166 	
167 	/**
168 	 */
169 	
170 	/**
171 	 * Warning
172 	 * g_mem_chunk_new has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
173 	 *  allocator instead
174 	 * Creates a new GMemChunk.
175 	 * Params:
176 	 * name = a string to identify the GMemChunk. It is not copied so it
177 	 * should be valid for the lifetime of the GMemChunk. It is
178 	 * only used in g_mem_chunk_print(), which is used for debugging.
179 	 * atomSize = the size, in bytes, of each element in the GMemChunk.
180 	 * areaSize = the size, in bytes, of each block of memory allocated to
181 	 * contain the atoms.
182 	 * type = the type of the GMemChunk. G_ALLOC_AND_FREE is used if the
183 	 * atoms will be freed individually. G_ALLOC_ONLY should be
184 	 * used if atoms will never be freed individually.
185 	 * G_ALLOC_ONLY is quicker, since it does not need to track
186 	 * free atoms, but it obviously wastes memory if you no longer
187 	 * need many of the atoms.
188 	 * Throws: ConstructionException GTK+ fails to create the object.
189 	 */
190 	public this (string name, int atomSize, gsize areaSize, int type)
191 	{
192 		// GMemChunk * g_mem_chunk_new (const gchar *name,  gint atom_size,  gsize area_size,  gint type);
193 		auto p = g_mem_chunk_new(Str.toStringz(name), atomSize, areaSize, type);
194 		if(p is null)
195 		{
196 			throw new ConstructionException("null returned by g_mem_chunk_new(Str.toStringz(name), atomSize, areaSize, type)");
197 		}
198 		this(cast(GMemChunk*) p);
199 	}
200 	
201 	/**
202 	 * Warning
203 	 * 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
204 	 * Allocates an atom of memory from a GMemChunk.
205 	 * Returns: a pointer to the allocated atom.
206 	 */
207 	public void* alloc()
208 	{
209 		// gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
210 		return g_mem_chunk_alloc(gMemChunk);
211 	}
212 	
213 	/**
214 	 * Warning
215 	 * 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
216 	 * Allocates an atom of memory from a GMemChunk, setting the memory to
217 	 * 0.
218 	 * Returns: a pointer to the allocated atom.
219 	 */
220 	public void* alloc0()
221 	{
222 		// gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
223 		return g_mem_chunk_alloc0(gMemChunk);
224 	}
225 	
226 	/**
227 	 * Warning
228 	 * 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
229 	 * Frees an atom in a GMemChunk. This should only be called if the
230 	 * GMemChunk was created with G_ALLOC_AND_FREE. Otherwise it will
231 	 * simply return.
232 	 * Params:
233 	 * mem = a pointer to the atom to free.
234 	 */
235 	public void free(void* mem)
236 	{
237 		// void g_mem_chunk_free (GMemChunk *mem_chunk,  gpointer mem);
238 		g_mem_chunk_free(gMemChunk, mem);
239 	}
240 	
241 	/**
242 	 * Warning
243 	 * g_mem_chunk_destroy has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
244 	 *  allocator instead
245 	 * Frees all of the memory allocated for a GMemChunk.
246 	 */
247 	public void destroy()
248 	{
249 		// void g_mem_chunk_destroy (GMemChunk *mem_chunk);
250 		g_mem_chunk_destroy(gMemChunk);
251 	}
252 	
253 	/**
254 	 * Warning
255 	 * g_mem_chunk_reset has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
256 	 *  allocator instead
257 	 * Resets a GMemChunk to its initial state. It frees all of the
258 	 * currently allocated blocks of memory.
259 	 */
260 	public void reset()
261 	{
262 		// void g_mem_chunk_reset (GMemChunk *mem_chunk);
263 		g_mem_chunk_reset(gMemChunk);
264 	}
265 	
266 	/**
267 	 * Warning
268 	 * g_mem_chunk_clean has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
269 	 *  allocator instead
270 	 * Frees any blocks in a GMemChunk which are no longer being used.
271 	 */
272 	public void clean()
273 	{
274 		// void g_mem_chunk_clean (GMemChunk *mem_chunk);
275 		g_mem_chunk_clean(gMemChunk);
276 	}
277 	
278 	/**
279 	 * Warning
280 	 * g_blow_chunks has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
281 	 *  allocator instead
282 	 * Calls g_mem_chunk_clean() on all GMemChunk objects.
283 	 */
284 	public static void blowChunks()
285 	{
286 		// void g_blow_chunks (void);
287 		g_blow_chunks();
288 	}
289 	
290 	/**
291 	 * Warning
292 	 * g_mem_chunk_info has been deprecated since version 2.10 and should not be used in newly-written code. Use the slice
293 	 *  allocator instead
294 	 * Outputs debugging information for all GMemChunk objects currently
295 	 * in use. It outputs the number of GMemChunk objects currently
296 	 * allocated, and calls g_mem_chunk_print() to output information on
297 	 * each one.
298 	 */
299 	public static void info()
300 	{
301 		// void g_mem_chunk_info (void);
302 		g_mem_chunk_info();
303 	}
304 }