-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_allocator.h
More file actions
95 lines (70 loc) · 2.27 KB
/
memory_allocator.h
File metadata and controls
95 lines (70 loc) · 2.27 KB
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
90
91
92
93
94
95
// Copyright Diaconescu Stefania Clara 313CA 2023-2024
#ifndef MEMORY_ALLOCATOR_H
#define MEMORY_ALLOCATOR_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "doubly_list.h"
typedef struct heap_t {
unsigned long start_addr;
unsigned int nr_lists, nr_bytes, type, capacity, memory;
doubly_linked_list_t **segr_lists;
} heap_t;
typedef struct index_t {
int index_malloc;
int index_free;
int nr_fragmentations;
int mem_alloc;
} index_t;
heap_t *
alloc_heap(unsigned long start_addr, unsigned int nr_lists,
unsigned int nr_bytes, unsigned int type);
void
init_heap(heap_t **heap, unsigned int nr_lists, unsigned int nr_bytes);
doubly_linked_list_t **
realloc_mat(doubly_linked_list_t **list, unsigned int *capacity);
int
verify_heap(heap_t **heap, unsigned int nr_bytes, unsigned int *i, int *equal);
unsigned int
pos_in_list(doubly_linked_list_t *list, unsigned long address);
void
insert_lists(heap_t **heap, unsigned int nr_bytes_residue, unsigned int *i);
int
find_address(doubly_linked_list_t *list, unsigned long address);
void
free_memory(heap_t **heap, doubly_linked_list_t **allocated, index_t *index,
unsigned long address);
void
malloc_bytes(heap_t **heap, doubly_linked_list_t **allocated,
unsigned int nr_bytes, index_t *index);
int
find_address(doubly_linked_list_t *list, unsigned long address);
void
free_memory_type0(heap_t **heap, dll_node_t *node);
int
find_index(doubly_linked_list_t *list, unsigned long address,
unsigned int index, unsigned int nr_bytes);
void
free_memory_type1(heap_t ***heap, dll_node_t *node, unsigned long address);
void
free_memory(heap_t **heap, doubly_linked_list_t **allocated, index_t *index,
unsigned long address);
unsigned int
find_end(unsigned int *bytes, unsigned int l, doubly_linked_list_t **allocated,
unsigned int nr_bytes);
void
write(doubly_linked_list_t **allocated, unsigned long address, int *seg,
char *date, unsigned int nr_bytes);
void
read(doubly_linked_list_t **allocated, unsigned long address, int *seg,
unsigned int nr_bytes);
unsigned int
free_mem(heap_t *heap);
unsigned int
free_blocks(heap_t *heap);
void
dump_memory(heap_t *heap, doubly_linked_list_t *allocated, index_t *index);
void
destroy_heap(heap_t **heap, doubly_linked_list_t **allocated);
#endif