Quash Shell  0.1
A simple yet powerfull shell program
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>

Go to the source code of this file.

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
The memory pool allocations are not thread safe

Function Documentation

◆ initialize_memory_pool()

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.

◆ memory_pool_alloc()

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

◆ memory_pool_strdup()

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