From 3ff11e451722d56fa248dfa45aae2b20943cf249 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Mon, 3 Nov 2025 12:02:37 -0500 Subject: Added assignment details as a README --- README.html | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 README.html (limited to 'README.html') diff --git a/README.html b/README.html new file mode 100644 index 0000000..8f85d97 --- /dev/null +++ b/README.html @@ -0,0 +1,121 @@ +

For this assignment, you will be writing a memory allocation library called libmalloc. This library should provide basic heap memory management features.

+

Required Features

+

The required interface for your library is as follows,

+
+void *allocate(size_t) 
+  Returns a pointer to an available region of heap memory of a specified number of bytes. 
+  If the allocation fails for some reason, return NULL instead. This function should use 
+  the sbrk syscall to grow the heap as needed, and should prioritize allocating memory 
+  from the free list if possible.
+
+  Returned pointers must be aligned to a 16 byte boundary and the allocated region must
+  be within the programs heap.
+
+  
+void release(void*)
+  Frees a region of memory allocated by the allocate function by adding it to the free 
+  list. This function should also handle coalescing contiguous memory regions on the 
+  free list at the time of release.
+
+  You may assume that the input argument is a pointer that has been returned by
+  allocate, and has not already been released.
+  
+
+typedef struct freelist_hdr freelist_hdr;
+  A struct for the header of memory regions on the free list. This type should
+  *not* be opaque externally to the library, and can be used for testing
+
+  
+freelist_hdr *list_head()
+  Returns a pointer to the head of the free list--can be used for testing
+
+

Other Requirements

+

Beyond the required interface, there are a few constraints on how your implementation must function.

+
    +
  1. Do not use any heap memory management libraries, including the standard library's implementations of malloc, free, etc. You must do all memory management manually, yourself. The only memory management function you can call is sbrk
  2. +
  3. If there exists space on the free list to service an allocation, you must use that space rather than growing the heap. 
  4. +
  5. You should include a C program which imports and tests your library in your submission. You do not need to use a unit test framework, though you may use check if you like.
  6. +
  7. Your submission should include the following, +
      +
    1. A Makefile for building a static library, as well as the test binary
    2. +
    3. An include file for your library
    4. +
    +
  8. +
+

Hints

+
    +
  1. Read Chapter 17 of the textbook. It provides near step by step instructions for this project.
  2. +
  3. You can get the initial memory address for the start of the heap by calling sbrk(0).
  4. +
  5. Not being able to use heap memory within your library will feel quite limiting. You will need to make generous use of global variables to track the necessary state information. 
  6. +
  7. C doesn't provide a mechanism for automatic module initialization. Because this library doesn't include an explicit init() function in its API, you will need to piggyback initialization on the first call to allocate(). Consider using a global variable to track whether the library has been initialized yet.
  8. +
  9. You can use subtraction on a pointer to embed headers prior to heap memory addresses. Just be careful to ensure that your library doesn't clobber these headers accidentally. 
  10. +
+

Grading Criteria

+

Submissions will be graded on the following criteria,

+

Library Correctness (30 pts)

+ + + + + + + + + + + + + + + + + + + + + + + +
CriteriaPoints
Basic allocation and release work correctly, without account for reuse of released blocks15
Blocks are correctly reused from the free list when possible7
Blocks in the free list are coalesced when possible3
Blocks in the free list are split when possible5
+

Testing (10 pts)

+ + + + + + + + + + + + + + + + + + + +
CriteriaPoints
Testing code exists and runs2
Testing code exists that leverages the list_head() function to validate the free list3
Testing code validates allocating and releasing memory5
+

Code Quality (10 pts)

+ + + + + + + + + + + + + + + + + + + +
CriteriaPoints
Library is well organized, non-public functions and data are declared as static3
Code is well documented using a combination of meaningful variable and function names, and comments2
Include file contains comments describing the behavior of each function in the interface.5
-- cgit v1.2.3