Contents

  1. Malloc Lab - Initial Step
  2. Free List Data Structure
  3. Common Macros
  4. Linked List Macros
  5. Binary Tree Macros
  6. Linked List Functions
  7. Binary Tree Functions
  8. mm_init
  9. mm_init
  10. Checking mm_init
  11. gdb init file
  12. Running gdb
  13. Testing mm_init

Malloc Lab - Initial Step[top]


Free List Data Structure[top]

Decide which data structure you will use to hold the free blocks:

Common Macros[top]

You may want to define a constant PROLOGSIZE to reflect the changed size if you want to use the payload of the prolog block for either the head sentinel of the linked list or the the root pointer of the binary tree.

It will be helpful to define these parameterized macros:

Linked List Macros[top]

If you are using the linked list data structure, you will need to define these macros

Binary Tree Macros[top]

If you are using the binary tree for the free blocks, you will need to define these macros:

Linked List Functions[top]

You will need to write functions to manage the free list

Binary Tree Functions[top]

If you are using a binary tree for the free blocks, you will need to write functions to manage the binary tree of free blocks:

mm_init[top]

For step 1, the goal is to modify mm_init to initialize your heap and insert the initial free block into your free block data structure AND to test that it is correct.

For testing mm_init and later functions, you will need to modify the functions:

You will then use the debugger, gdb, to check that your modifications to mm_init are correct and what you expect.

mm_init[top]

Checking mm_init[top]

Compile the malloc lab with the -g option to include debugging information.

The first compiles with optimization level 2 (no debuggin info); the second compiles with debugging info (not optimized)

When switching between optimized and debugging versions, be sure to remove the other version by typing

      make clean
    

Then just type

      make 
    

to rebuild using your current settings for CFLAGS.

gdb init file[top]

You may find it handy to have several things automatically defined each time you start gdb.

To do so create a file - say gdbinit - in the malloc lab directory and type in these gdb statements:

      set listsize 35

      define hh
      call mm_checkheap(1)
      end

      b mm_init
      b mm_malloc
      b mm_free
    

As a result, each time you start gdb:

Running gdb[top]

Start gdb:

      gdb mdriver
or
      gdb -x gdbinit mdriver    (to read and execute the commands in gdbinit)
    

At the gdb prompt type r to run mdriver optionally with any command line arguments that mdriver accepts (such as -a and -f)

To run mdriver, without checking the team structure, with throughput turned off (debug set to 1) on the sample trace file trace0.rep in the traces subdirectory:

      (gdb) r -a -d 1 -f traces/trace0.rep

    

Common gdb commands

Testing mm_init[top]

After you have made the changes to mm_init (and printblock and mm_checkheap), run the debugger.

After the initializations, execute the hh command to print out your heap before and after the call to extend_heap and after the call to mm_insert.

Check the output printed by hh to see if your initializations and your mm_insert are working as you expect.