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