![]() |
|
|
Question: If we are trying to make a list, where each entry contains a list of size-x free blocks, how can we mark where each list starts without a global array? Answer: You are allowed to have these pointers as global variables, but I recommend storing the array at the bottom of the heap... Afterall, it's a big chunk of memory where you can do whatever you want.
Question: Am I allowed to use memmove instead of memcpy in realloc? Answer: Yes. Enjoy!
Question: As a starting point, my partner and i simply typed the code from the book into mm.c (incl. find_fit and place) and ran it, but we got a core dump and an error on 'trace 0' Answer: I don't believe the book's code is faulty. Perhaps you made a mistake in transcribing from the book to your own code? You should attempt running it in gdb and see where it segfaults.
Question: I noticed that the given implementation of realloc() uses memcpy() to copy data; are we allowed to use this in our implementation as well? Answer: Yes.
Question: I have a question regarding the mm_realloc function. If mm_realloc is called with a size that is smaller than the current block size, then it seems that one should be able to just put the new size in the header and footer and then return a pointer to the same block. However, implementing this method results in the error message: mm_realloc did not preserve the data from the old block Answer: The semantics for realloc when it gets a size smaller than the old block is that the bottom n bytes are to remain the same.
Question: Am I allowed to use memmove instead of memcpy in realloc? Answer: Sure! Enjoy.
Question: In working on the malloc lab, I first implemented mm.c with an implicit list and after achieving success then implemented mm.c with a free list using LIFO. Answer: LIFO isn't a very space efficient policy. It doesn't surprise me that it yielded a worse-than-random performance in this respect. But, it doesn't involve a lot of overhead, so it doesn't surprise me that it was a slight time win -- but since implicit lists are also pretty cheap, especially when frees and allocs are mixed in ways that prevent long searches, I'm not surprised that it is only sligtly faster.
Question: When we run mtest for all the test cases, we get a seg fault at binary-bal.rep. However, when we run each test case seperately, they all work. Is this a problem with the grading script, or an error in our code? Answer: You might not be reinitializing correctly. Check your mm_init() function to make sure it does exactly what it's supposed to. That's about all I can think of off hand. Your code shouldn't crash when mtest runs through everything. You may want to run it in gdb to see where it's crashing.
Question: What would cause the error "ERROR: mem_sbrk failed. Ran out of memory..."? Answer: Remember that you use sbrk to extend the heap. If the heap gets too large, that means too many pages have been allocated to it before it starts encroaching on stack space. Question: Are we allowed to declare static global variables? Also, where are static global variables managed in the virtual memory? Answer: It's okay to declare some void *, int, or other base type variables as static global. Don't declare any global structs, etc, as the lab says. Question: How is casting to (size_t *) different from casting to (void *)? Answer: Casting to size_t * makes makes a pointer to a size_t object. Casting to void * creates a generic pointer. The difference is that void objects do not have any size, a void pointer is merely a standardized way to pass pointers to anything around.
Question: How do you test mm.c, i.e. how do you use mtest.c? Answer: Just type make to compile mtest. Then run ./mtest and it will run all the trace files. ./mtest -h will give you some more options.
Question: Our group was thinking of an implementation of Malloc that is somewhat different from the suggested Segregated free lists that was described in class. We'd like to know your opinions regarding the idea. Answer: Anything you can think of to do better is always great. If you feel you have the time, implement it and see if it works. However, perhaps you should make sure you have a working implementation before tackling anything too complicated. |