-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_allocator.h
89 lines (65 loc) · 2.44 KB
/
my_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
File: my_allocator.h
Author: R.Bettati
Department of Computer Science
Texas A&M University
Date : 08/02/08
Modified:
*/
#ifndef _my_allocator_h_ // include file only once
#define _my_allocator_h_
/*--------------------------------------------------------------------------*/
/* DEFINES */
/*--------------------------------------------------------------------------*/
/* -- (none) -- */
/*--------------------------------------------------------------------------*/
/* INCLUDES */
/*--------------------------------------------------------------------------*/
#include <vector>
#include <iostream>
/*--------------------------------------------------------------------------*/
/* DATA STRUCTURES */
/*--------------------------------------------------------------------------*/
typedef struct h{
struct h *next;
struct h *prev;
unsigned int size;
bool isFree;
unsigned int marker;
}Header;
typedef struct flist{
Header *first;
Header *last;
int seg_size;
}Flist;
typedef void * Addr;
Addr memstart;
std::vector<Flist> flist;
/*--------------------------------------------------------------------------*/
/* FORWARDS */
/*--------------------------------------------------------------------------*/
/* -- (none) -- */
/*--------------------------------------------------------------------------*/
/* MODULE MY_ALLOCATOR */
/*--------------------------------------------------------------------------*/
unsigned int init_allocator(unsigned int _basic_block_size,
unsigned int _length);
/* This function initializes the memory allocator and makes a portion of
’_length’ bytes available. The allocator uses a ’_basic_block_size’ as
its minimal unit of allocation. The function returns the amount of
memory made available to the allocator. ./a.If an error occurred,
it returns 0.
*/
void release_allocator();
/* This function returns any allocated memory to the operating system.
After this function is called, any allocation fails.
*/
Addr my_malloc(unsigned int _length);
/* Allocate _length number of bytes of free memory and returns the
address of the allocated portion. Returns 0 when out of memory. */
int my_free(Addr _a);
/* Frees the section of physical memory previously allocated
using ’my_malloc’. Returns 0 if everything ok. */
int index_search(std::vector<Flist> flist, Header* head);
Header* allocator_coalesce(Header* h);
#endif