gbowne1 version of implementation with more implementations done #4
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GitSharedSettings">
|
||||||
|
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
|
15
main.c
15
main.c
@ -1,11 +1,19 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
<<<<<<< HEAD
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
=======
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
>>>>>>> origin/main
|
||||||
|
|
||||||
#define ALIGN16(s) (((s) + 15) & ~0x0F)
|
#define ALIGN16(s) (((s) + 15) & ~0x0F)
|
||||||
#define BLOCK_SIZE sizeof(struct block)
|
#define BLOCK_SIZE sizeof(struct block)
|
||||||
|
<<<<<<< HEAD
|
||||||
#define MINIMUM_BLOCK_SIZE (sizeof(struct block) + 16)
|
#define MINIMUM_BLOCK_SIZE (sizeof(struct block) + 16)
|
||||||
|
=======
|
||||||
|
#define MINIMUM_BLOCK_SIZE 4
|
||||||
|
>>>>>>> origin/main
|
||||||
|
|
||||||
/// The memory block's header.
|
/// The memory block's header.
|
||||||
struct block
|
struct block
|
||||||
@ -28,12 +36,18 @@ struct block *extend_heap(size_t s)
|
|||||||
if (s < MINIMUM_BLOCK_SIZE)
|
if (s < MINIMUM_BLOCK_SIZE)
|
||||||
s = MINIMUM_BLOCK_SIZE;
|
s = MINIMUM_BLOCK_SIZE;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
struct block *b = (struct block *)sbrk(0); // Get the current break
|
struct block *b = (struct block *)sbrk(0); // Get the current break
|
||||||
|
|
||||||
// Add the size of the block header to the requested size
|
// Add the size of the block header to the requested size
|
||||||
s += BLOCK_SIZE;
|
s += BLOCK_SIZE;
|
||||||
|
|
||||||
if (sbrk(s) == (void *)-1) // Extend the break by s bytes
|
if (sbrk(s) == (void *)-1) // Extend the break by s bytes
|
||||||
|
=======
|
||||||
|
struct block* b = (struct block*)syscall(SYS_brk, NULL);
|
||||||
|
|
||||||
|
if ((void*)syscall(SYS_brk, (char*)(b + 1) + s) == (void*)-1)
|
||||||
|
>>>>>>> origin/main
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
b->size = s;
|
b->size = s;
|
||||||
@ -269,6 +283,7 @@ int main()
|
|||||||
|
|
||||||
printf("Test 1: %i\n", *a);
|
printf("Test 1: %i\n", *a);
|
||||||
printf("Test 2: %i\n", *b);
|
printf("Test 2: %i\n", *b);
|
||||||
|
printf("Heap Size: %zu Bytes\n", get_heap_size());
|
||||||
|
|
||||||
free(a);
|
free(a);
|
||||||
free(b);
|
free(b);
|
||||||
|
Loading…
Reference in New Issue
Block a user