-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm.h
81 lines (68 loc) · 1.93 KB
/
mm.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
/**
* @file mm.h
* @brief Provides an interface for the memory allocator used in malloclab
*/
#ifndef MM_H__
#define MM_H__ 1
#include <stdbool.h>
#include <stdio.h>
#ifdef DRIVER
/* declare functions for driver tests */
extern void *mm_malloc(size_t size);
extern void mm_free(void *ptr);
extern void *mm_realloc(void *ptr, size_t size);
extern void *mm_calloc(size_t nmemb, size_t size);
#else
/* declare functions for interpositioning */
/**
* @brief Allocate memory in the heap of at least `size` bytes.
*
* @param[in] size The minimum size of bytes to allocate.
*
* @return A pointer to the beginning of the allocated bytes.
*/
extern void *malloc(size_t size);
/**
* @brief Marks an allocated block as free.
*
* @param[in] ptr A pointer to the beginning of the allocated payload.
*/
extern void free(void *ptr);
/**
* @brief Resize an allocated block.
*
* @param[in] ptr A pointer to the beginning of the allocated payload.
* @param[in] size The new size of the allocated block.
*
* @return A pointer to the beginning of the allocated bytes.
*/
extern void *realloc(void *ptr, size_t size);
/**
* @brief Allocate an array of `nmemb` elements of `size` bytes each
*
* Allocate memory in the heap of at least `size` * `nmemb` bytes
* initialized to all zeros.
*
* @param[in] nmemb The number of elements in the array.
* @param[in] size The size of each element of the array.
*
* @return A pointer to the first element of the array.
*/
extern void *calloc(size_t nmemb, size_t size);
#endif
/**
* @brief Initialize the heap.
*
* @return True on success, False otherwise.
*/
extern bool mm_init(void);
/* This is for debugging. Returns false if error encountered */
/**
* @brief Check the heap for inconsistencies.
*
* @param[in] line The line number this function is being called at.
*
* @return True if the heap is consistent, False otherwise.
*/
extern bool mm_checkheap(int line);
#endif /* mm.h */