-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocator.h
59 lines (46 loc) · 1.42 KB
/
allocator.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* File: allocator.h
* -----------------
* Interface file for the custom heap allocator.
*/
#ifndef _ALLOCATOR_H
#define _ALLOCATOR_H
#include <stdbool.h> // for bool
#include <stddef.h> // for size_t
// Alignment requirement for all blocks
#define ALIGNMENT 8
// maximum size of block that must be accommodated
#define MAX_REQUEST_SIZE (1 << 30)
/* Function: myinit
* ----------------
* This must be called by a client before making any allocation
* requests. The function returns true if initialization was successful,
* or false otherwise. The myinit function can be called to reset
* the heap to an empty state. When running against a set of
* of test scripts, our test harness calls myinit before starting
* each new script.
*/
bool myinit(void *segment_start, size_t segment_size);
/* Function: mymalloc
* ------------------
* Custom version of malloc.
*/
void *mymalloc(size_t size);
/* Function: myrealloc
* -------------------
* Custom version of realloc.
*/
void *myrealloc(void *ptr, size_t new_size);
/* Function: myfree
* ----------------
* Custom version of free.
*/
void myfree(void *ptr);
/* Function: validate_heap
* -----------------------
* This is the hook for your heap consistency checker. Returns true
* if all is well, or false on any problem. This function is
* called periodically by the test harness to check the state of
* the heap allocator.
*/
bool validate_heap(void);
#endif