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-Slices.html
27  * outPack = glib
28  * outFile = MemorySlice
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = MemorySlice
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_slice_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * module aliases:
48  * local aliases:
49  * overrides:
50  */
51 
52 module glib.MemorySlice;
53 
54 public  import gtkc.glibtypes;
55 
56 private import gtkc.glib;
57 private import glib.ConstructionException;
58 
59 
60 
61 
62 
63 
64 /**
65  * Description
66  * Memory slices provide a space-efficient and multi-processing scalable
67  * way to allocate equal-sized pieces of memory, just like the original
68  * GMemChunks (from GLib <= 2.8), while avoiding their excessive
69  * memory-waste, scalability and performance problems.
70  * To achieve these goals, the slice allocator uses a sophisticated,
71  * layered design that has been inspired by Bonwick's slab allocator
72  * [6].
73  * It uses posix_memalign() to optimize allocations of many equally-sized
74  * chunks, and has per-thread free lists (the so-called magazine layer)
75  * to quickly satisfy allocation requests of already known structure sizes.
76  * This is accompanied by extra caching logic to keep freed memory around
77  * for some time before returning it to the system. Memory that is unused
78  * due to alignment constraints is used for cache colorization (random
79  * distribution of chunk addresses) to improve CPU cache utilization. The
80  * caching layer of the slice allocator adapts itself to high lock contention
81  * to improve scalability.
82  * The slice allocator can allocate blocks as small as two pointers, and
83  * unlike malloc(), it does not reserve extra space per block. For large block
84  * sizes, g_slice_new() and g_slice_alloc() will automatically delegate to the
85  * system malloc() implementation. For newly written code it is recommended
86  * to use the new g_slice API instead of g_malloc() and
87  * friends, as long as objects are not resized during their lifetime and the
88  * object size used at allocation time is still available when freeing.
89  * $(DDOC_COMMENT example)
90  * $(DDOC_COMMENT example)
91  */
92 public class MemorySlice
93 {
94 	
95 	/**
96 	 */
97 	
98 	/**
99 	 * Allocates a block of memory from the slice allocator.
100 	 * The block adress handed out can be expected to be aligned
101 	 * to at least 1 * sizeof (void*),
102 	 * though in general slices are 2 * sizeof (void*) bytes aligned,
103 	 * if a malloc() fallback implementation is used instead,
104 	 * the alignment may be reduced in a libc dependent fashion.
105 	 * Note that the underlying slice allocation mechanism can
106 	 * be changed with the G_SLICE=always-malloc
107 	 * environment variable.
108 	 * Since 2.10
109 	 * Params:
110 	 * blockSize = the number of bytes to allocate
111 	 * Returns: a pointer to the allocated memory block
112 	 */
113 	public static void* alloc(gsize blockSize)
114 	{
115 		// gpointer g_slice_alloc (gsize block_size);
116 		return g_slice_alloc(blockSize);
117 	}
118 	
119 	/**
120 	 * Allocates a block of memory via g_slice_alloc()
121 	 * and initialize the returned memory to 0.
122 	 * Note that the underlying slice allocation mechanism can
123 	 * be changed with the G_SLICE=always-malloc
124 	 * environment variable.
125 	 * Since 2.10
126 	 * Params:
127 	 * blockSize = the number of bytes to allocate
128 	 * Returns: a pointer to the allocated block
129 	 */
130 	public static void* alloc0(gsize blockSize)
131 	{
132 		// gpointer g_slice_alloc0 (gsize block_size);
133 		return g_slice_alloc0(blockSize);
134 	}
135 	
136 	/**
137 	 * Allocates a block of memory from the slice allocator and copies
138 	 * block_size bytes into it from mem_block.
139 	 * Since 2.14
140 	 * Params:
141 	 * blockSize = the number of bytes to allocate
142 	 * memBlock = the memory to copy
143 	 * Returns: a pointer to the allocated memory block
144 	 */
145 	public static void* copy(gsize blockSize, void* memBlock)
146 	{
147 		// gpointer g_slice_copy (gsize block_size,  gconstpointer mem_block);
148 		return g_slice_copy(blockSize, memBlock);
149 	}
150 	
151 	/**
152 	 * Frees a block of memory. The memory must have been allocated via
153 	 * g_slice_alloc() or g_slice_alloc0()
154 	 * and the block_size has to match the size specified upon allocation.
155 	 * Note that the exact release behaviour can be changed with the
156 	 * G_DEBUG=gc-friendly environment variable,
157 	 * also see G_SLICE for related debugging options.
158 	 * Since 2.10
159 	 * Params:
160 	 * blockSize = the size of the block
161 	 * memBlock = a pointer to the block to free
162 	 */
163 	public static void free1(gsize blockSize, void* memBlock)
164 	{
165 		// void g_slice_free1 (gsize block_size,  gpointer mem_block);
166 		g_slice_free1(blockSize, memBlock);
167 	}
168 	
169 	/**
170 	 * Frees a linked list of memory blocks of structure type type.
171 	 * The memory blocks must be equal-sized, allocated via
172 	 * g_slice_alloc() or g_slice_alloc0()
173 	 * and linked together by a next pointer (similar to GSList). The offset
174 	 * of the next field in each block is passed as third argument.
175 	 * Note that the exact release behaviour can be changed with the
176 	 * G_DEBUG=gc-friendly environment variable,
177 	 * also see G_SLICE for related debugging options.
178 	 * Since 2.10
179 	 * Params:
180 	 * blockSize = the size of the blocks
181 	 * memChain = a pointer to the first block of the chain
182 	 * nextOffset = the offset of the next field in the blocks
183 	 */
184 	public static void freeChainWithOffset(gsize blockSize, void* memChain, gsize nextOffset)
185 	{
186 		// void g_slice_free_chain_with_offset (gsize block_size,  gpointer mem_chain,  gsize next_offset);
187 		g_slice_free_chain_with_offset(blockSize, memChain, nextOffset);
188 	}
189 }