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.
|
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...
|
|
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
#define IMPLEMENT_DEQUE_MEMORY_POOL |
( |
|
struct_name, |
|
|
|
type |
|
) |
| |
void initialize_memory_pool |
( |
size_t |
size | ) |
|
Allocate the memory pool.
- Parameters
-
size | The 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
-
size | Size 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
-
str | Pointer to the string to duplicate |
- Returns
- A copy of str allocated in the memory pool