nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GLIB - Library of useful routines for C programming |
2 | * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald |
||
3 | * |
||
4 | * This library is free software; you can redistribute it and/or |
||
5 | * modify it under the terms of the GNU Lesser General Public |
||
6 | * License as published by the Free Software Foundation; either |
||
7 | * version 2 of the License, or (at your option) any later version. |
||
8 | * |
||
9 | * This library 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 GNU |
||
12 | * Lesser General Public License for more details. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Lesser General Public |
||
15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
||
20 | * file for a list of people on the GLib Team. See the ChangeLog |
||
21 | * files for a list of changes. These files are distributed with |
||
22 | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
||
23 | */ |
||
24 | |||
25 | #include "config.h" |
||
26 | |||
27 | #include "gtrashstack.h" |
||
28 | |||
29 | /** |
||
30 | * SECTION:trash_stack |
||
31 | * @title: Trash Stacks |
||
32 | * @short_description: maintain a stack of unused allocated memory chunks |
||
33 | * |
||
34 | * A #GTrashStack is an efficient way to keep a stack of unused allocated |
||
35 | * memory chunks. Each memory chunk is required to be large enough to hold |
||
36 | * a #gpointer. This allows the stack to be maintained without any space |
||
37 | * overhead, since the stack pointers can be stored inside the memory chunks. |
||
38 | * |
||
39 | * There is no function to create a #GTrashStack. A %NULL #GTrashStack* |
||
40 | * is a perfectly valid empty stack. |
||
41 | * |
||
42 | * There is no longer any good reason to use #GTrashStack. If you have |
||
43 | * extra pieces of memory, free() them and allocate them again later. |
||
44 | * |
||
45 | * Deprecated: 2.48: #GTrashStack is deprecated without replacement |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * GTrashStack: |
||
50 | * @next: pointer to the previous element of the stack, |
||
51 | * gets stored in the first `sizeof (gpointer)` |
||
52 | * bytes of the element |
||
53 | * |
||
54 | * Each piece of memory that is pushed onto the stack |
||
55 | * is cast to a GTrashStack*. |
||
56 | * |
||
57 | * Deprecated: 2.48: #GTrashStack is deprecated without replacement |
||
58 | */ |
||
59 | |||
60 | /** |
||
61 | * g_trash_stack_push: |
||
62 | * @stack_p: a #GTrashStack |
||
63 | * @data_p: (not nullable): the piece of memory to push on the stack |
||
64 | * |
||
65 | * Pushes a piece of memory onto a #GTrashStack. |
||
66 | * Deprecated: 2.48: #GTrashStack is deprecated without replacement |
||
67 | */ |
||
68 | void |
||
69 | g_trash_stack_push (GTrashStack **stack_p, |
||
70 | gpointer data_p) |
||
71 | { |
||
72 | GTrashStack *data = (GTrashStack *) data_p; |
||
73 | |||
74 | data->next = *stack_p; |
||
75 | *stack_p = data; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * g_trash_stack_pop: |
||
80 | * @stack_p: a #GTrashStack |
||
81 | * |
||
82 | * Pops a piece of memory off a #GTrashStack. |
||
83 | * |
||
84 | * Returns: the element at the top of the stack |
||
85 | * Deprecated: 2.48: #GTrashStack is deprecated without replacement |
||
86 | */ |
||
87 | gpointer |
||
88 | g_trash_stack_pop (GTrashStack **stack_p) |
||
89 | { |
||
90 | GTrashStack *data; |
||
91 | |||
92 | data = *stack_p; |
||
93 | if (data) |
||
94 | { |
||
95 | *stack_p = data->next; |
||
96 | /* NULLify private pointer here, most platforms store NULL as |
||
97 | * subsequent 0 bytes |
||
98 | */ |
||
99 | data->next = NULL; |
||
100 | } |
||
101 | |||
102 | return data; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * g_trash_stack_peek: |
||
107 | * @stack_p: a #GTrashStack |
||
108 | * |
||
109 | * Returns the element at the top of a #GTrashStack |
||
110 | * which may be %NULL. |
||
111 | * |
||
112 | * Returns: the element at the top of the stack |
||
113 | * Deprecated: 2.48: #GTrashStack is deprecated without replacement |
||
114 | */ |
||
115 | gpointer |
||
116 | g_trash_stack_peek (GTrashStack **stack_p) |
||
117 | { |
||
118 | GTrashStack *data; |
||
119 | |||
120 | data = *stack_p; |
||
121 | |||
122 | return data; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * g_trash_stack_height: |
||
127 | * @stack_p: a #GTrashStack |
||
128 | * |
||
129 | * Returns the height of a #GTrashStack. |
||
130 | * |
||
131 | * Note that execution of this function is of O(N) complexity |
||
132 | * where N denotes the number of items on the stack. |
||
133 | * |
||
134 | * Returns: the height of the stack |
||
135 | * Deprecated: 2.48: #GTrashStack is deprecated without replacement |
||
136 | */ |
||
137 | guint |
||
138 | g_trash_stack_height (GTrashStack **stack_p) |
||
139 | { |
||
140 | GTrashStack *data; |
||
141 | guint i = 0; |
||
142 | |||
143 | for (data = *stack_p; data; data = data->next) |
||
144 | i++; |
||
145 | |||
146 | return i; |
||
147 | } |