Fri, 10 Jun 2022 20:42:36 -0500
fix memory leak when using purple accounts
Testing Done:
ran test_account_manager and test_notification (from /r/1502 where I first encountered that leak) in valgrind -> no more leak and no new invalid read/write
Reviewed at https://reviews.imfreedom.org/r/1503/
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
1 | /* |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
2 | * Purple |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
3 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
5 | * numerous to list here. Please refer to the COPYRIGHT file distributed |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
6 | * with this source distribution |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
7 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or (at |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
11 | * your option) any later version. |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
12 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, but |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
16 | * General Public License for more details. |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
17 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
21 | */ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
22 | |
|
40474
1341be8e3402
Make it so only libpurple can directly include libpurple header files.
Gary Kramlich <grim@reaperworld.com>
parents:
35774
diff
changeset
|
23 | #if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION) |
|
1341be8e3402
Make it so only libpurple can directly include libpurple header files.
Gary Kramlich <grim@reaperworld.com>
parents:
35774
diff
changeset
|
24 | # error "only <purple.h> may be included directly" |
|
1341be8e3402
Make it so only libpurple can directly include libpurple header files.
Gary Kramlich <grim@reaperworld.com>
parents:
35774
diff
changeset
|
25 | #endif |
|
1341be8e3402
Make it so only libpurple can directly include libpurple header files.
Gary Kramlich <grim@reaperworld.com>
parents:
35774
diff
changeset
|
26 | |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
27 | #ifndef PURPLE_MEMORY_POOL_H |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
28 | #define PURPLE_MEMORY_POOL_H |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
29 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
30 | #include <glib-object.h> |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
31 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
32 | #define PURPLE_TYPE_MEMORY_POOL (purple_memory_pool_get_type()) |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
33 | #define PURPLE_MEMORY_POOL(obj) \ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
34 | (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_MEMORY_POOL, PurpleMemoryPool)) |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
35 | #define PURPLE_MEMORY_POOL_CLASS(klass) \ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
36 | (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_MEMORY_POOL, PurpleMemoryPoolClass)) |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
37 | #define PURPLE_IS_MEMORY_POOL(obj) \ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
38 | (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_MEMORY_POOL)) |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
39 | #define PURPLE_IS_MEMORY_POOL_CLASS(klass) \ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
40 | (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_MEMORY_POOL)) |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
41 | #define PURPLE_MEMORY_POOL_GET_CLASS(obj) \ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
42 | (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_MEMORY_POOL, PurpleMemoryPoolClass)) |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
43 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
44 | typedef struct _PurpleMemoryPool PurpleMemoryPool; |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
45 | typedef struct _PurpleMemoryPoolClass PurpleMemoryPoolClass; |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
46 | |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
47 | /** |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
48 | * PurpleMemoryPool: |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
49 | * |
|
41208
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
50 | * A #PurpleMemoryPool allows allocating many small objects within a single |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
51 | * memory range and releasing them all at once using a single call. This |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
52 | * prevents memory fragmentation and improves performance when used properly. |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
53 | * Its purpose is to act as an internal storage for other object private |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
54 | * structures, like tree nodes, string chunks, list elements. |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
55 | * |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
56 | * Current implementation is not optimized for releasing individual objects, |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
57 | * so it may be extremely inefficient, when misused. On every memory allocation, |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
58 | * it checks if there is enough space in current block. If there is not enough |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
59 | * room here, it creates another block of memory. On pool destruction or calling |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
60 | * #purple_memory_pool_cleanup, the whole block chain will be freed, using only |
|
48baac6c8989
Remove unnecessary gtk-doc comments and move them where possible from libpurple/[d-m]*.h
Gary Kramlich <grim@reaperworld.com>
parents:
40474
diff
changeset
|
61 | * one #g_free call for every block. |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
62 | */ |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
63 | struct _PurpleMemoryPool |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
64 | { |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
65 | /*< private >*/ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
66 | GObject parent_instance; |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
67 | }; |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
68 | |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
69 | /** |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
70 | * PurpleMemoryPoolClass: |
|
35774
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
71 | * @palloc: alloates memory for a specific memory pool subclass, |
|
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
72 | * see #purple_memory_pool_alloc. |
|
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
73 | * @pfree: frees memory allocated within a pool, see #purple_memory_pool_free. |
|
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
74 | * May be %NULL. |
|
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
75 | * @cleanup: frees (or marks as unused) all memory allocated within a pool. |
|
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
76 | * See #purple_memory_pool_cleanup. |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
77 | * |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
78 | * Base class for #PurpleMemoryPool objects. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
79 | */ |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
80 | struct _PurpleMemoryPoolClass |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
81 | { |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
82 | /*< private >*/ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
83 | GObjectClass parent_class; |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
84 | |
|
35774
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
85 | /*< public >*/ |
|
35652
1dc7369ff9f9
Trie, memory pool: we don't really need block_size pref to be that strict
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35651
diff
changeset
|
86 | gpointer (*palloc)(PurpleMemoryPool *pool, gsize size, guint alignment); |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
87 | gpointer (*pfree)(PurpleMemoryPool *pool, gpointer mem); |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
88 | void (*cleanup)(PurpleMemoryPool *pool); |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
89 | |
|
35774
9227a7757e92
Comments: PurpleSmiley
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35773
diff
changeset
|
90 | /*< private >*/ |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
91 | void (*purple_reserved1)(void); |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
92 | void (*purple_reserved2)(void); |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
93 | void (*purple_reserved3)(void); |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
94 | void (*purple_reserved4)(void); |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
95 | }; |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
96 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
97 | G_BEGIN_DECLS |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
98 | |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
99 | /** |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
100 | * purple_memory_pool_get_type: |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
101 | * |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
102 | * Returns: the #GType for a #PurpleMemoryPool. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
103 | */ |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
104 | GType |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
105 | purple_memory_pool_get_type(void); |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
106 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
107 | /** |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
108 | * purple_memory_pool_new: |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
109 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
110 | * Creates a new memory pool. |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
111 | * |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
112 | * Returns: the new #PurpleMemoryPool. |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
113 | */ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
114 | PurpleMemoryPool * |
|
35652
1dc7369ff9f9
Trie, memory pool: we don't really need block_size pref to be that strict
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35651
diff
changeset
|
115 | purple_memory_pool_new(void); |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
116 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
117 | /** |
|
35666
ca4afaddaffa
Memory pool: fix some issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
118 | * purple_memory_pool_set_block_size: |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
119 | * @pool: the memory pool. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
120 | * @block_size: the new default block size. |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
121 | * |
|
35666
ca4afaddaffa
Memory pool: fix some issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
122 | * Sets new default block size for a memory pool. You might want to call this |
|
ca4afaddaffa
Memory pool: fix some issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
123 | * before any allocation, to have it applied to the every created block. |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
124 | */ |
|
35666
ca4afaddaffa
Memory pool: fix some issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
125 | void |
|
ca4afaddaffa
Memory pool: fix some issues
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
126 | purple_memory_pool_set_block_size(PurpleMemoryPool *pool, gulong block_size); |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
127 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
128 | /** |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
129 | * purple_memory_pool_alloc: |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
130 | * @pool: the memory pool. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
131 | * @size: the size of memory to be allocated. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
132 | * @alignment: the alignment of memory block (should be a power of two). |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
133 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
134 | * Allocates an aligned memory block within a pool. |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
135 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
136 | * Returns: the pointer to a memory block. This should be freed with |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
137 | * a call to #purple_memory_pool_free. |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
138 | */ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
139 | gpointer |
|
35652
1dc7369ff9f9
Trie, memory pool: we don't really need block_size pref to be that strict
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35651
diff
changeset
|
140 | purple_memory_pool_alloc(PurpleMemoryPool *pool, gsize size, guint alignment); |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
141 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
142 | /** |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
143 | * purple_memory_pool_alloc0: |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
144 | * @pool: the memory pool. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
145 | * @size: the size of memory to be allocated. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
146 | * @alignment: the alignment of memory block (should be a power of two). |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
147 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
148 | * Allocates an aligned memory block within a pool and sets its contents to |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
149 | * zeros. |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
150 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
151 | * Returns: the pointer to a memory block. This should be freed with |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
152 | * a call to #purple_memory_pool_free. |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
153 | */ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
154 | gpointer |
|
35652
1dc7369ff9f9
Trie, memory pool: we don't really need block_size pref to be that strict
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35651
diff
changeset
|
155 | purple_memory_pool_alloc0(PurpleMemoryPool *pool, gsize size, guint alignment); |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
156 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
157 | /** |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
158 | * purple_memory_pool_free: |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
159 | * @pool: the memory pool. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
160 | * @mem: the pointer to a memory block. |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
161 | * |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
162 | * Frees a memory allocated within a memory pool. This can be a no-op in certain |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
163 | * implementations. Thus, it don't need to be called in every case. Thus, the |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
164 | * freed memory is wasted until you call #purple_memory_pool_cleanup |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
165 | * or destroy the @pool. |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
166 | */ |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
167 | void |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
168 | purple_memory_pool_free(PurpleMemoryPool *pool, gpointer mem); |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
169 | |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
170 | /** |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
171 | * purple_memory_pool_cleanup: |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
172 | * @pool: the memory pool. |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
173 | * |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
174 | * Marks all memory allocated within a memory pool as not used. It may free |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
175 | * resources, but don't have to. |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
176 | */ |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
177 | void |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
178 | purple_memory_pool_cleanup(PurpleMemoryPool *pool); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
179 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
180 | /** |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
181 | * purple_memory_pool_strdup: |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
182 | * @pool: the memory pool. |
|
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
183 | * @str: the string to duplicate. |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
184 | * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
185 | * Duplicates a string using a memory allocated within a memory pool. If @str is |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
186 | * %NULL, it returns %NULL. The returned string should be freed with g_free() |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
187 | * when no longer needed. |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
188 | * |
|
35772
2224568d8bd2
Comments: memory pool
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35666
diff
changeset
|
189 | * Returns: a newly-allocated copy of @str. |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
190 | */ |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
191 | gchar * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
192 | purple_memory_pool_strdup(PurpleMemoryPool *pool, const gchar *str); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35649
diff
changeset
|
193 | |
|
35649
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
194 | G_END_DECLS |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
195 | |
|
eff51bb998b0
Implement PurpleMemoryPool class
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
196 | #endif /* PURPLE_MEMORY_POOL_H */ |