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 module glib.MemorySlice;
26 
27 private import gtkc.glib;
28 public  import gtkc.glibtypes;
29 
30 
31 /** */
32 public struct MemorySlice
33 {
34 	T* mewSlice(T)()
35 	{
36 		return cast(T*)g_slice_alloc(T.sizeof);
37 	}
38 	
39 	T* mewSlice0(T)()
40 	{
41 		return cast(T*)g_slice_alloc0(T.sizeof);
42 	}
43 	
44 	T* dup(T)(T* memBlock)
45 	{
46 		return cast(T*)g_slice_copy(T.sizeof, memBlock);
47 	}
48 	
49 	void free(T)(T* memBlock)
50 	{
51 		g_slice_free1(T.sizeof, memBlock);
52 	}
53 
54 	/**
55 	 */
56 
57 	/**
58 	 * Allocates a block of memory from the slice allocator.
59 	 * The block adress handed out can be expected to be aligned
60 	 * to at least 1 * sizeof (void*),
61 	 * though in general slices are 2 * sizeof (void*) bytes aligned,
62 	 * if a malloc() fallback implementation is used instead,
63 	 * the alignment may be reduced in a libc dependent fashion.
64 	 * Note that the underlying slice allocation mechanism can
65 	 * be changed with the [`G_SLICE=always-malloc`][G_SLICE]
66 	 * environment variable.
67 	 *
68 	 * Params:
69 	 *     blockSize = the number of bytes to allocate
70 	 *
71 	 * Return: a pointer to the allocated memory block, which will be %NULL if and
72 	 *     only if @mem_size is 0
73 	 *
74 	 * Since: 2.10
75 	 */
76 	public static void* sliceAlloc(size_t blockSize)
77 	{
78 		return g_slice_alloc(blockSize);
79 	}
80 
81 	/**
82 	 * Allocates a block of memory via g_slice_alloc() and initializes
83 	 * the returned memory to 0. Note that the underlying slice allocation
84 	 * mechanism can be changed with the [`G_SLICE=always-malloc`][G_SLICE]
85 	 * environment variable.
86 	 *
87 	 * Params:
88 	 *     blockSize = the number of bytes to allocate
89 	 *
90 	 * Return: a pointer to the allocated block, which will be %NULL if and only
91 	 *     if @mem_size is 0
92 	 *
93 	 * Since: 2.10
94 	 */
95 	public static void* sliceAlloc0(size_t blockSize)
96 	{
97 		return g_slice_alloc0(blockSize);
98 	}
99 
100 	/**
101 	 * Allocates a block of memory from the slice allocator
102 	 * and copies @block_size bytes into it from @mem_block.
103 	 *
104 	 * @mem_block must be non-%NULL if @block_size is non-zero.
105 	 *
106 	 * Params:
107 	 *     blockSize = the number of bytes to allocate
108 	 *     memBlock = the memory to copy
109 	 *
110 	 * Return: a pointer to the allocated memory block, which will be %NULL if and
111 	 *     only if @mem_size is 0
112 	 *
113 	 * Since: 2.14
114 	 */
115 	public static void* sliceCopy(size_t blockSize, void* memBlock)
116 	{
117 		return g_slice_copy(blockSize, memBlock);
118 	}
119 
120 	/**
121 	 * Frees a block of memory.
122 	 *
123 	 * The memory must have been allocated via g_slice_alloc() or
124 	 * g_slice_alloc0() and the @block_size has to match the size
125 	 * specified upon allocation. Note that the exact release behaviour
126 	 * can be changed with the [`G_DEBUG=gc-friendly`][G_DEBUG] environment
127 	 * variable, also see [`G_SLICE`][G_SLICE] for related debugging options.
128 	 *
129 	 * If @mem_block is %NULL, this function does nothing.
130 	 *
131 	 * Params:
132 	 *     blockSize = the size of the block
133 	 *     memBlock = a pointer to the block to free
134 	 *
135 	 * Since: 2.10
136 	 */
137 	public static void sliceFree1(size_t blockSize, void* memBlock)
138 	{
139 		g_slice_free1(blockSize, memBlock);
140 	}
141 
142 	/**
143 	 * Frees a linked list of memory blocks of structure type @type.
144 	 *
145 	 * The memory blocks must be equal-sized, allocated via
146 	 * g_slice_alloc() or g_slice_alloc0() and linked together by a
147 	 * @next pointer (similar to #GSList). The offset of the @next
148 	 * field in each block is passed as third argument.
149 	 * Note that the exact release behaviour can be changed with the
150 	 * [`G_DEBUG=gc-friendly`][G_DEBUG] environment variable, also see
151 	 * [`G_SLICE`][G_SLICE] for related debugging options.
152 	 *
153 	 * If @mem_chain is %NULL, this function does nothing.
154 	 *
155 	 * Params:
156 	 *     blockSize = the size of the blocks
157 	 *     memChain = a pointer to the first block of the chain
158 	 *     nextOffset = the offset of the @next field in the blocks
159 	 *
160 	 * Since: 2.10
161 	 */
162 	public static void sliceFreeChainWithOffset(size_t blockSize, void* memChain, size_t nextOffset)
163 	{
164 		g_slice_free_chain_with_offset(blockSize, memChain, nextOffset);
165 	}
166 
167 	/** */
168 	public static long sliceGetConfig(GSliceConfig ckey)
169 	{
170 		return g_slice_get_config(ckey);
171 	}
172 
173 	/** */
174 	public static long* sliceGetConfigState(GSliceConfig ckey, long address, uint* nValues)
175 	{
176 		return g_slice_get_config_state(ckey, address, nValues);
177 	}
178 
179 	/** */
180 	public static void sliceSetConfig(GSliceConfig ckey, long value)
181 	{
182 		g_slice_set_config(ckey, value);
183 	}
184 }