-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtalloc.h
34 lines (27 loc) · 1.47 KB
/
talloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdlib.h>
#include "value.h"
#ifndef _TALLOC
#define _TALLOC
/* Replacement for malloc that stores the pointers allocated. It should store
* the pointers in some kind of list; a linked list would do fine, but insert
* here whatever code you'll need to do so; don't call functions in the
* pre-existing linkedlist.h. Otherwise you'll end up with circular
* dependencies, since you're going to modify the linked list to use talloc. */
void *talloc(size_t size);
/* Free all pointers allocated by talloc, as well as whatever memory you
* allocated in lists to hold those pointers. */
void tfree();
/* Replacement for the C function "exit", that consists of two lines: it calls
* tfree before calling exit. It's useful to have later on; if an error happens,
* you can exit your program, and all memory is automatically cleaned up. */
void texit(int status);
/* Returns the amount of memory currently in use by talloc, including the memory
* used to store the talloc active list. Does not compensate for alignment;
* that is, calling malloc(1) will in reality allocate more than 1 byte on the
* heap, but this function only returns the amount of memory requested through
* talloc, in this case 1, in addition to the memory needed for the list itself.
* Similarly, internal and external fragmentation are not accounted for with
* respect to Value structs, which are 4+8+8 bytes, which will likely be allocated
* as either 24 or 32 bytes total. */
size_t tallocMemoryCount();
#endif