This repository was archived by the owner on Jan 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathumalloc.h
More file actions
39 lines (33 loc) · 1.3 KB
/
umalloc.h
File metadata and controls
39 lines (33 loc) · 1.3 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
#include <stdlib.h>
#include <stdbool.h>
#define ALIGNMENT 16 /* The alignment of all payloads returned by umalloc */
#define ALIGN(size) (((size) + (ALIGNMENT-1)) & ~(ALIGNMENT-1))
/*
* memory_block_t - Represents a block of memory managed by the heap. The
* struct can be left as is, or modified for your design.
* In the current design bit0 is the allocated bit
* bits 1-3 are unused.
* and the remaining 60 bit represent the size.
*/
typedef struct memory_block_struct {
size_t block_size_alloc;
struct memory_block_struct *next;
} memory_block_t;
// Helper Functions. Their parameters may be edited if you change their
// signature in umalloc.c. Do not change their purpose.
bool is_allocated(memory_block_t *block);
void allocate(memory_block_t *block);
void deallocate(memory_block_t *block);
size_t get_size(memory_block_t *block);
memory_block_t *get_next(memory_block_t *block);
void put_block(memory_block_t *block, size_t size, bool alloc);
void *get_payload(memory_block_t *block);
memory_block_t *get_block(void *payload);
memory_block_t *find(size_t size);
memory_block_t *extend(size_t size);
memory_block_t *split(memory_block_t *block, size_t size);
memory_block_t *coalesce(memory_block_t *block);
// Portion that may not be edited
int uinit();
void *umalloc(size_t size);
void ufree(void *ptr);