williamr@2
|
1 |
/* GLIB sliced memory - fast threaded memory chunk allocator
|
williamr@2
|
2 |
* Copyright (C) 2005 Tim Janik
|
williamr@2
|
3 |
* Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This library is free software; you can redistribute it and/or
|
williamr@2
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
williamr@2
|
7 |
* License as published by the Free Software Foundation; either
|
williamr@2
|
8 |
* version 2 of the License, or (at your option) any later version.
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This library is distributed in the hope that it will be useful,
|
williamr@2
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
williamr@2
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
williamr@2
|
13 |
* Lesser General Public License for more details.
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
williamr@2
|
16 |
* License along with this library; if not, write to the
|
williamr@2
|
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
williamr@2
|
18 |
* Boston, MA 02111-1307, USA.
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
#ifndef __G_SLICE_H__
|
williamr@2
|
21 |
#define __G_SLICE_H__
|
williamr@2
|
22 |
|
williamr@2
|
23 |
#ifndef __G_MEM_H__
|
williamr@2
|
24 |
#error Include <glib.h> instead of <gslice.h>
|
williamr@2
|
25 |
#endif
|
williamr@2
|
26 |
|
williamr@2
|
27 |
#include <glib/gtypes.h>
|
williamr@2
|
28 |
|
williamr@2
|
29 |
G_BEGIN_DECLS
|
williamr@2
|
30 |
|
williamr@2
|
31 |
/* slices - fast allocation/release of small memory blocks
|
williamr@2
|
32 |
*/
|
williamr@2
|
33 |
IMPORT_C gpointer g_slice_alloc (gsize block_size) G_GNUC_MALLOC;
|
williamr@2
|
34 |
IMPORT_C gpointer g_slice_alloc0 (gsize block_size) G_GNUC_MALLOC;
|
williamr@2
|
35 |
IMPORT_C void g_slice_free1 (gsize block_size,
|
williamr@2
|
36 |
gpointer mem_block);
|
williamr@2
|
37 |
IMPORT_C void g_slice_free_chain_with_offset (gsize block_size,
|
williamr@2
|
38 |
gpointer mem_chain,
|
williamr@2
|
39 |
gsize next_offset);
|
williamr@2
|
40 |
#define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type)))
|
williamr@2
|
41 |
#define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type)))
|
williamr@2
|
42 |
/* g_slice_free (MemoryBlockType,
|
williamr@2
|
43 |
* MemoryBlockType *mem_block);
|
williamr@2
|
44 |
* g_slice_free_chain (MemoryBlockType,
|
williamr@2
|
45 |
* MemoryBlockType *first_chain_block,
|
williamr@2
|
46 |
* memory_block_next_field);
|
williamr@2
|
47 |
* pseudo prototypes for the macro
|
williamr@2
|
48 |
* definitions following below.
|
williamr@2
|
49 |
*/
|
williamr@2
|
50 |
|
williamr@2
|
51 |
/* we go through extra hoops to ensure type safety */
|
williamr@2
|
52 |
#define g_slice_free(type, mem) do { \
|
williamr@2
|
53 |
if (1) g_slice_free1 (sizeof (type), (mem)); \
|
williamr@2
|
54 |
else (void) ((type*) 0 == (mem)); \
|
williamr@2
|
55 |
} while (0)
|
williamr@2
|
56 |
#define g_slice_free_chain(type, mem_chain, next) do { \
|
williamr@2
|
57 |
if (1) g_slice_free_chain_with_offset (sizeof (type), \
|
williamr@2
|
58 |
(mem_chain), G_STRUCT_OFFSET (type, next)); \
|
williamr@2
|
59 |
else (void) ((type*) 0 == (mem_chain)); \
|
williamr@2
|
60 |
} while (0)
|
williamr@2
|
61 |
|
williamr@2
|
62 |
|
williamr@2
|
63 |
/* --- internal debugging API --- */
|
williamr@2
|
64 |
typedef enum {
|
williamr@2
|
65 |
G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
|
williamr@2
|
66 |
G_SLICE_CONFIG_BYPASS_MAGAZINES,
|
williamr@2
|
67 |
G_SLICE_CONFIG_WORKING_SET_MSECS,
|
williamr@2
|
68 |
G_SLICE_CONFIG_COLOR_INCREMENT,
|
williamr@2
|
69 |
G_SLICE_CONFIG_CHUNK_SIZES,
|
williamr@2
|
70 |
G_SLICE_CONFIG_CONTENTION_COUNTER
|
williamr@2
|
71 |
} GSliceConfig;
|
williamr@2
|
72 |
void g_slice_set_config (GSliceConfig ckey, gint64 value);
|
williamr@2
|
73 |
gint64 g_slice_get_config (GSliceConfig ckey);
|
williamr@2
|
74 |
gint64* g_slice_get_config_state (GSliceConfig ckey, gint64 address, guint *n_values);
|
williamr@2
|
75 |
|
williamr@2
|
76 |
G_END_DECLS
|
williamr@2
|
77 |
|
williamr@2
|
78 |
#endif /* __G_SLICE_H__ */
|