Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Operating Systems (COMP2211)

Coursework 2: Memory management


Submission You must submit your work via gradescope by the deadline. No late submissions will be accepted without prior agreement via the Mitigating circumstances procedure.

Deadline See Gradescope

Weighting This piece of summative coursework is worth 25% of the module grade.

Learning outcomes In this coursework you will demonstrate:

- An understanding of user space memory management

- The ability to program components of an operating system.

When programming in the C programming language dynamic memory allocation is facilitated by calls to malloc, free, realloc and calloc. “Under the hood” these calls are dynamically expanding and shrinking the heap memory segment of the process.

Your task is to implement functions similar to malloc and free such that they meet the following specification. You should provide your implementation in a new file called memory _management.c and a corresponding header file memory _management.h. Your files should be suitable for location in the user directory.


malloc (10 marks)

The malloc function allocates the specified number of bytes and returns a pointer to the allocated memory. The memory is not initialized. If the requested size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free.

- the function should have the prototype void * _malloc(int size)

- the function should return a void pointer to the start of the allocated memory

- the function should allocate memory on the heap

- the function should implement a mechanism which is space efficient


free (10 marks)

The free function frees the memory space pointed to by the parameter which must have been returned by a previous call to _malloc(). Otherwise, or if free has already been called on the pointer before, undefined behaviour occurs. If the pointer is NULL, no operation is performed.

- the function should have the prototype void _free(void *ptr)

- the function should “free” the memory and make it available for subsequent allocations

- the function should implement a mechanism which is space efficient


Advanced (5 marks)

- the pointer returned by _malloc() should be suitably aligned for any type of variable

- the _free() function should return the memory to the operating system when it is appropriate