I've no idea here...
[gtkD.git] / src / glib / MemorySlice.d
bloba4d63438c5349a20bcfc8737cfaab8e61b943a47
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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-Slices.html
26 * outPack = glib
27 * outFile = MemorySlice
28 * strct =
29 * realStrct=
30 * ctorStrct=
31 * clss = MemorySlice
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_slice_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * local aliases:
48 module glib.MemorySlice;
50 private import glib.glibtypes;
52 private import lib.glib;
55 /**
56 * Description
57 * Memory slices provide a space-efficient and multi-processing scalable
58 * way to allocate equal-sized pieces of memory, just like the original
59 * GMemChunks (from GLib <= 2.8), while avoiding their excessive
60 * memory-waste, scalability and performance problems.
61 * To achieve these goals, the slice allocator uses a sophisticated,
62 * layered design that has been inspired by Bonwick's slab allocator
63 * [5].
64 * It uses posix_memalign() to optimize allocations of many equally-sized
65 * chunks, and has per-thread free lists (the so-called magazine layer)
66 * to quickly satisfy allocation requests of already known structure sizes.
67 * This is accompanied by extra caching logic to keep freed memory around
68 * for some time before returning it to the system. Memory that is unused
69 * due to alignment constraints is used for cache colorization (random
70 * distribution of chunk addresses) to improve CPU cache utilization. The
71 * caching layer of the slice allocator adapts itself to high lock contention
72 * to improve scalability.
73 * The slice allocator can allocate blocks as small as two pointers, and
74 * unlike malloc(), it does not reserve extra space per block. For large block
75 * sizes, g_slice_new() and g_slice_alloc() will automatically delegate to the
76 * system malloc() implementation. For newly written code it is recommended
77 * to use the new g_slice API instead of g_malloc() and
78 * friends, as long as objects are not resized during their lifetime and the
79 * object size used at allocation time is still available when freeing.
80 * Example1.Using the slice allocator
81 * gchar *mem[10000];
82 * gint i;
83 * /+* Allocate 10000 blocks. +/
84 * for (i = 0; i < 10000; i++)
85 * {
86 * mem[i] = g_slice_alloc (50);
87 * /+* Fill in the memory with some junk. +/
88 * for (j = 0; j < 50; j++)
89 * mem[i][j] = i * j;
90 * }
91 * /+* Now free all of the blocks. +/
92 * for (i = 0; i < 10000; i++)
93 * {
94 * g_slice_free1 (50, mem[i]);
95 * }
96 * Example2.Using the slice allocator with data structures
97 * GRealArray *array;
98 * /+* Allocate one block, using the g_slice_new() macro. +/
99 * array = g_slice_new (GRealArray);
100 * /+* We can now use array just like a normal pointer to a structure. +/
101 * array->data = NULL;
102 * array->len = 0;
103 * array->alloc = 0;
104 * array->zero_terminated = (zero_terminated ? 1 : 0);
105 * array->clear = (clear ? 1 : 0);
106 * array->elt_size = elt_size;
107 * /+* We can free the block, so it can be reused. +/
108 * g_slice_free (GRealArray, array);
110 public class MemorySlice
117 * Allocates a block of memory from the slice allocator.
118 * The block adress handed out is guaranteed to be aligned
119 * to at least 2 * sizeof (void*).
120 * Note that the underlying slice allocation mechanism can
121 * be changed with the G_SLICE=always-malloc
122 * environment variable.
123 * block_size:
124 * the number of bytes to allocate
125 * Returns:
126 * a pointer to the allocated memory block
127 * Since 2.10
129 public static void* alloc(uint blockSize)
131 // gpointer g_slice_alloc (gsize block_size);
132 return g_slice_alloc(blockSize);
136 * Allocates a block of memory via g_slice_alloc()
137 * and initialize the returned memory to 0.
138 * Note that the underlying slice allocation mechanism can
139 * be changed with the G_SLICE=always-malloc
140 * environment variable.
141 * block_size:
142 * the number of bytes to allocate
143 * Returns:
144 * a pointer to the allocated block
145 * Since 2.10
147 public static void* alloc0(uint blockSize)
149 // gpointer g_slice_alloc0 (gsize block_size);
150 return g_slice_alloc0(blockSize);
154 * Frees a block of memory. The memory must have been allocated via
155 * g_slice_alloc() or g_slice_alloc0()
156 * and the block_size has to match the size specified upon allocation.
157 * Note that the exact release behaviour can be changed with the
158 * G_DEBUG=gc-friendly environment variable.
159 * block_size:
160 * the size of the block
161 * mem_block:
162 * a pointer to the block to free
163 * Since 2.10
165 public static void free1(uint blockSize, void* memBlock)
167 // void g_slice_free1 (gsize block_size, gpointer mem_block);
168 g_slice_free1(blockSize, memBlock);
172 * Frees a linked list of memory blocks of structure type type.
173 * The memory blocks must be equal-sized, allocated via
174 * g_slice_alloc() or g_slice_alloc0()
175 * and linked together by a next pointer (similar to GSList). The offset
176 * of the next field in each block is passed as third argument.
177 * Note that the exact release behaviour can be changed with the
178 * G_DEBUG=gc-friendly environment variable.
179 * block_size:
180 * the size of the blocks
181 * mem_chain:
182 * a pointer to the first block of the chain
183 * next_offset:
184 * the offset of the next field in the blocks
185 * Since 2.10
187 public static void freeChainWithOffset(uint blockSize, void* memChain, uint nextOffset)
189 // void g_slice_free_chain_with_offset (gsize block_size, gpointer mem_chain, gsize next_offset);
190 g_slice_free_chain_with_offset(blockSize, memChain, nextOffset);