Add some more cases to the app-id unit tests
[glib.git] / glib / gtrashstack.c
blob3a0d0bf1629eb0952cfaa01f2a6f83cea454604c
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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/>.
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/.
25 #include "config.h"
27 #include "gtrashstack.h"
29 /**
30 * SECTION:trash_stack
31 * @title: Trash Stacks
32 * @short_description: maintain a stack of unused allocated memory chunks
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.
39 * There is no function to create a #GTrashStack. A %NULL #GTrashStack*
40 * is a perfectly valid empty stack.
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.
45 * Deprecated: 2.48: #GTrashStack is deprecated without replacement
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
54 * Each piece of memory that is pushed onto the stack
55 * is cast to a GTrashStack*.
57 * Deprecated: 2.48: #GTrashStack is deprecated without replacement
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
65 * Pushes a piece of memory onto a #GTrashStack.
66 * Deprecated: 2.48: #GTrashStack is deprecated without replacement
68 void
69 g_trash_stack_push (GTrashStack **stack_p,
70 gpointer data_p)
72 GTrashStack *data = (GTrashStack *) data_p;
74 data->next = *stack_p;
75 *stack_p = data;
78 /**
79 * g_trash_stack_pop:
80 * @stack_p: a #GTrashStack
82 * Pops a piece of memory off a #GTrashStack.
84 * Returns: the element at the top of the stack
85 * Deprecated: 2.48: #GTrashStack is deprecated without replacement
87 gpointer
88 g_trash_stack_pop (GTrashStack **stack_p)
90 GTrashStack *data;
92 data = *stack_p;
93 if (data)
95 *stack_p = data->next;
96 /* NULLify private pointer here, most platforms store NULL as
97 * subsequent 0 bytes
99 data->next = NULL;
102 return data;
106 * g_trash_stack_peek:
107 * @stack_p: a #GTrashStack
109 * Returns the element at the top of a #GTrashStack
110 * which may be %NULL.
112 * Returns: the element at the top of the stack
113 * Deprecated: 2.48: #GTrashStack is deprecated without replacement
115 gpointer
116 g_trash_stack_peek (GTrashStack **stack_p)
118 GTrashStack *data;
120 data = *stack_p;
122 return data;
126 * g_trash_stack_height:
127 * @stack_p: a #GTrashStack
129 * Returns the height of a #GTrashStack.
131 * Note that execution of this function is of O(N) complexity
132 * where N denotes the number of items on the stack.
134 * Returns: the height of the stack
135 * Deprecated: 2.48: #GTrashStack is deprecated without replacement
137 guint
138 g_trash_stack_height (GTrashStack **stack_p)
140 GTrashStack *data;
141 guint i = 0;
143 for (data = *stack_p; data; data = data->next)
144 i++;
146 return i;