forked from TstevetsT/ListMalloc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMalloc_README
More file actions
73 lines (54 loc) · 3.28 KB
/
Malloc_README
File metadata and controls
73 lines (54 loc) · 3.28 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
MALLOC(2) Linux Programmer's Manual MALLOC(2)
NAME
l_malloc
SYNOPSIS
void *l_malloc (unsigned int size);
void *l_calloc(unsigned int nmemb, unsigned int size);
void *l_realloc(void *ptr, unsigned int size);
void l_free(void *ptr);
DESCRIPTION
Blocks
--------------------- <-- Memory Ptr of Header
|| Size + Status || 4 Bytes Lowest bit is used for flag
--------------------- <-- Memory Ptr Addr Returned
|| Free Space || Space available to the calling process
---------------------
Allocated block headers are 4 bytes in size. The minimum block
allocation is 4 bytes. With no space for user data. This will keep
free blocks aligned in the heap. If any blocks are 4 bytes in size
it will automatically be added to the allocation.
Size (4 Bytes)
Size of allocated blocks can be up to a default 100,000 bytes in size
change HEAPMAX to a large size to modify the max intial size of the heap
located in malloc.asm
Status (LSB) - uses AND operation to determine whether a status flag is
utilized or not.
00000000 - indicates the block is free
00000001 - indicates the block is allocated
When a block of memory is freed the entire heap will be checked for blocks
to coalesce due to the absence of a previous pointer and next pointer within
the header information for a given block.
l_calloc() and l_realloc() are extensions of l_malloc(). When one of these
companion functions are called l_malloc() will be invoked. l_calloc ()
allocates a block of memory and then the resulting block of memory is filled
with zeroes. l_realloc() allocates a new block of memory when the first
argument is null of the requested size. If a pointer is passed to l_realloc()
in the first argument it will allocate a block of memory of a the specified
size in argument two and then copy the first argument pointer into the new
allocated block of memory. If the new memory block you copy into is smaller
than the previous pointer then part of the copy will not be successful.
l_free() is used to free blocks of memory that have been allocated by
l_malloc(). When l_free() frees a block of memory it will then merge the
entire heap starting from the highest address (or the beginning of the heap).
If l_free() finds that the entire heap is empty when the caller invokes
l_free() it will free the entire heap back to the kernel.
RETURN VALUE
On success, l_malloc(), l_calloc(), l_realloc(), returns a pointer to a
reserved block of memory in the heap. On error or failure, NULL is returned.
On success, l_free() release the memory pointed to by ptr. If the ptr
is NULL no action is taken.
NOTES
The priority for malloc is ensuring the maximum amount of space available
for the calling process/function. Usable space has more priority than
speed, and this resulted in a smaller header but more overhead to process
changes to the heap during coalescence (consolidating free space).