Trash Stacks

## Trash Stacks Trash Stacks — maintain a stack of unused allocated memory chunks |

## Functions

void | g_trash_stack_push ()
gpointer | g_trash_stack_pop ()
gpointer | g_trash_stack_peek ()
guint | g_trash_stack_height ()

## Types and Values

struct | GTrashStack

## Includes

    #include <gmodule.h>

## Description

A GTrashStack is an efficient way to keep a stack of unused allocated memory chunks. Each memory chunk is required to be large enough to hold a gpointer. This allows the stack to be maintained without any space overhead, since the stack pointers can be stored inside the memory chunks.

There is no function to create a GTrashStack. A `NULL` GTrashStack* is a perfectly valid empty stack.

There is no longer any good reason to use GTrashStack. If you have extra pieces of memory, `free()` them and allocate them again later.

## Functions

### g_trash_stack_push ()

    void
    g_trash_stack_push (GTrashStack **stack_p,
                        gpointer data_p);

`g_trash_stack_push` has been deprecated since version 2.48 and should not be used in newly-written code.

GTrashStack is deprecated without replacement

Pushes a piece of memory onto a GTrashStack.

#### Parameters

stack_p | a GTrashStack |
data_p | the piece of memory to push on the stack. | [not nullable]

### g_trash_stack_pop ()

    gpointer
    g_trash_stack_pop (GTrashStack **stack_p);

`g_trash_stack_pop` has been deprecated since version 2.48 and should not be used in newly-written code.

GTrashStack is deprecated without replacement

Pops a piece of memory off a GTrashStack.

#### Parameters

stack_p | a GTrashStack |

#### Returns

the element at the top of the stack

### g_trash_stack_peek ()

    gpointer
    g_trash_stack_peek (GTrashStack **stack_p);

`g_trash_stack_peek` has been deprecated since version 2.48 and should not be used in newly-written code.

GTrashStack is deprecated without replacement

Returns the element at the top of a GTrashStack which may be `NULL`.

#### Parameters

stack_p | a GTrashStack |

#### Returns

the element at the top of the stack

### g_trash_stack_height ()

    guint
    g_trash_stack_height (GTrashStack **stack_p);

`g_trash_stack_height` has been deprecated since version 2.48 and should not be used in newly-written code.

GTrashStack is deprecated without replacement

Returns the height of a GTrashStack.

Note that execution of this function is of O(N) complexity where N denotes the number of items on the stack.

#### Parameters

stack_p | a GTrashStack |

#### Returns

the height of the stack

## Types and Values

### struct GTrashStack

    struct GTrashStack {
      GTrashStack *next;
    };

`GTrashStack` has been deprecated since version 2.48 and should not be used in newly-written code.

GTrashStack is deprecated without replacement

Each piece of memory that is pushed onto the stack is cast to a GTrashStack*.

#### Members

GTrashStack *`next`; | pointer to the previous element of the stack, gets stored in the first `sizeof (gpointer)` bytes of the element |