-
Notifications
You must be signed in to change notification settings - Fork 1
/
malloc.h
66 lines (54 loc) · 1.33 KB
/
malloc.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
#ifndef _MALLOC_H_
#define _MALLOC_H_
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*MACROS*/
#define NAIVEBLOCK_SZ 8
#define BLOCK_SZ sizeof(blockhead)
/*Structs*/
/**
* struct naive_block - stores metadata for each block
* @total_bytes: total number of bytes allocated
*/
typedef struct naive_block
{
size_t total_bytes;
} naiveblock;
/**
* struct block_head - stores metadata for each block
* @total_bytes: total number of bytes allocated
* @used_bytes: number of occupied bytes used
*/
typedef struct block_head
{
size_t total_bytes;
size_t used_bytes;
} blockhead;
/**
* struct heap_data - Struct for storing heap data
* @first_block: pointer to first block of metadata
* @naive_block: pointer to first block for naive
* @heap_size: Total size of the heap in bytes
* @heap_free: Amount of heap free to use in bytes
* @numblock: The number of blocks in the heap
*/
typedef struct heap_data
{
blockhead *first_block;
naiveblock *naive_block;
size_t heap_size;
size_t heap_free;
size_t numblock;
} heap_data;
/*Prototypes*/
void *naive_malloc(size_t size);
naiveblock *naive_hopper(size_t size);
void *_malloc(size_t size);
blockhead *block_hopper(size_t size);
void _free(void *ptr);
void *_calloc(size_t nmemb, size_t size);
void *_realloc(void *ptr, size_t size);
#endif