|
Packit |
ae235b |
/* GLIB - Library of useful routines for C programming
|
|
Packit |
ae235b |
* Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This library is free software; you can redistribute it and/or
|
|
Packit |
ae235b |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
ae235b |
* License as published by the Free Software Foundation; either
|
|
Packit |
ae235b |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
ae235b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
ae235b |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
ae235b |
* Lesser General Public License for more details.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
ae235b |
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/*
|
|
Packit |
ae235b |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
|
Packit |
ae235b |
* file for a list of people on the GLib Team. See the ChangeLog
|
|
Packit |
ae235b |
* files for a list of changes. These files are distributed with
|
|
Packit |
ae235b |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "config.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "gtrashstack.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* SECTION:trash_stack
|
|
Packit |
ae235b |
* @title: Trash Stacks
|
|
Packit |
ae235b |
* @short_description: maintain a stack of unused allocated memory chunks
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* A #GTrashStack is an efficient way to keep a stack of unused allocated
|
|
Packit |
ae235b |
* memory chunks. Each memory chunk is required to be large enough to hold
|
|
Packit |
ae235b |
* a #gpointer. This allows the stack to be maintained without any space
|
|
Packit |
ae235b |
* overhead, since the stack pointers can be stored inside the memory chunks.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* There is no function to create a #GTrashStack. A %NULL #GTrashStack*
|
|
Packit |
ae235b |
* is a perfectly valid empty stack.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* There is no longer any good reason to use #GTrashStack. If you have
|
|
Packit |
ae235b |
* extra pieces of memory, free() them and allocate them again later.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Deprecated: 2.48: #GTrashStack is deprecated without replacement
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* GTrashStack:
|
|
Packit |
ae235b |
* @next: pointer to the previous element of the stack,
|
|
Packit |
ae235b |
* gets stored in the first `sizeof (gpointer)`
|
|
Packit |
ae235b |
* bytes of the element
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Each piece of memory that is pushed onto the stack
|
|
Packit |
ae235b |
* is cast to a GTrashStack*.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Deprecated: 2.48: #GTrashStack is deprecated without replacement
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_trash_stack_push:
|
|
Packit |
ae235b |
* @stack_p: a #GTrashStack
|
|
Packit |
ae235b |
* @data_p: (not nullable): the piece of memory to push on the stack
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Pushes a piece of memory onto a #GTrashStack.
|
|
Packit |
ae235b |
* Deprecated: 2.48: #GTrashStack is deprecated without replacement
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
void
|
|
Packit |
ae235b |
g_trash_stack_push (GTrashStack **stack_p,
|
|
Packit |
ae235b |
gpointer data_p)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GTrashStack *data = (GTrashStack *) data_p;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data->next = *stack_p;
|
|
Packit |
ae235b |
*stack_p = data;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_trash_stack_pop:
|
|
Packit |
ae235b |
* @stack_p: a #GTrashStack
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Pops a piece of memory off a #GTrashStack.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns: the element at the top of the stack
|
|
Packit |
ae235b |
* Deprecated: 2.48: #GTrashStack is deprecated without replacement
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
gpointer
|
|
Packit |
ae235b |
g_trash_stack_pop (GTrashStack **stack_p)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GTrashStack *data;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data = *stack_p;
|
|
Packit |
ae235b |
if (data)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
*stack_p = data->next;
|
|
Packit |
ae235b |
/* NULLify private pointer here, most platforms store NULL as
|
|
Packit |
ae235b |
* subsequent 0 bytes
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
data->next = NULL;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return data;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_trash_stack_peek:
|
|
Packit |
ae235b |
* @stack_p: a #GTrashStack
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns the element at the top of a #GTrashStack
|
|
Packit |
ae235b |
* which may be %NULL.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns: the element at the top of the stack
|
|
Packit |
ae235b |
* Deprecated: 2.48: #GTrashStack is deprecated without replacement
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
gpointer
|
|
Packit |
ae235b |
g_trash_stack_peek (GTrashStack **stack_p)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GTrashStack *data;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
data = *stack_p;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return data;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_trash_stack_height:
|
|
Packit |
ae235b |
* @stack_p: a #GTrashStack
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns the height of a #GTrashStack.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Note that execution of this function is of O(N) complexity
|
|
Packit |
ae235b |
* where N denotes the number of items on the stack.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns: the height of the stack
|
|
Packit |
ae235b |
* Deprecated: 2.48: #GTrashStack is deprecated without replacement
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
guint
|
|
Packit |
ae235b |
g_trash_stack_height (GTrashStack **stack_p)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GTrashStack *data;
|
|
Packit |
ae235b |
guint i = 0;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
for (data = *stack_p; data; data = data->next)
|
|
Packit |
ae235b |
i++;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return i;
|
|
Packit |
ae235b |
}
|