Quash Shell  0.1
A simple yet powerfull shell program
 All Classes Files Functions Variables Typedefs Enumerations Macros
Macros | Functions
memory_pool.h File Reference

An abstraction of malloc that allows for all allocations in the pool to be free'd with a single call to destroy_memory_pool(). Allocations to the memory pool should NOT be manually free'd with a call to free(). More...

#include <stdlib.h>
#include "deque.h"

Go to the source code of this file.

Macros

#define IMPLEMENT_DEQUE_MEMORY_POOL(struct_name, type)
 Generates a memory_pool_alloc() based set of functions for use with a structure generated by IMPLEMENT_DEQUE_STRUCT. More...
 

Functions

void initialize_memory_pool (size_t size)
 Allocate the memory pool. More...
 
void * memory_pool_alloc (size_t size)
 Reserve some space in the memory pool and returns a unique address that can be written to and read from. This can be thought of exactly like malloc() without the requirement of calling free() directly on the returned pointer. More...
 
void destroy_memory_pool ()
 Free all memory allocated in the memory pool.
 
char * memory_pool_strdup (const char *str)
 A version of strdup() that allocates the duplicate to the memory pool rather than with malloc directly. More...
 

Detailed Description

An abstraction of malloc that allows for all allocations in the pool to be free'd with a single call to destroy_memory_pool(). Allocations to the memory pool should NOT be manually free'd with a call to free().

Warning
FOR THE QUASH PROJECT, DO NOT USE OR COPY ANY OF THESE FUNCTIONS YOURSELF. This is a simple garbage collector to fix memory leak problems resulting from the parser, generated by bison, encountering syntax errors in the input that would be very difficult or impossible to fix without this mechanism. Generally, hand crafted c code should be able to manage it's heap allocations directly with malloc and free. We would like for you to become comfortable with malloc based memory management. YOU WILL BE PENALIZED FOR USING ANYTHING IN THIS FILE TO HIDE MEMORY LEAKS.
The memory pool allocations are not thread safe

Macro Definition Documentation

#define IMPLEMENT_DEQUE_MEMORY_POOL (   struct_name,
  type 
)

Generates a memory_pool_alloc() based set of functions for use with a structure generated by IMPLEMENT_DEQUE_STRUCT.

Parameters
struct_nameThe name of the structure
typeThe name of the type of elements stored in the struct_name structure
See Also
IMPLEMENT_DEQUE_STRUCT, PROTOTYPE_DEQUE, IMPLEMENT_DEQUE_MEMORY_POOL, memory_pool_alloc()

Function Documentation

void initialize_memory_pool ( size_t  size)

Allocate the memory pool.

Parameters
sizeThe initial size of the memory pool. If this value is zero then a default size of one is used.
void* memory_pool_alloc ( size_t  size)

Reserve some space in the memory pool and returns a unique address that can be written to and read from. This can be thought of exactly like malloc() without the requirement of calling free() directly on the returned pointer.

Parameters
sizeSize in bytes of the requested reserved space
Returns
A pointer to a unique array of size bytes
char* memory_pool_strdup ( const char *  str)

A version of strdup() that allocates the duplicate to the memory pool rather than with malloc directly.

Parameters
strPointer to the string to duplicate
Returns
A copy of str allocated in the memory pool