Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Memory Allocation (Please explain why u chose the answer) Consider boundary-t

ID: 656390 • Letter: 1

Question

1. Memory Allocation (Please explain why u chose the answer)

Consider boundary-tag dynamic memory allocation and dealloaction. Assume that there are 100 units of "space" in our heap and we wish to process the following list of memory allocation/deallocation commands in the order listed allocate hi(30) allocate h2(45) allocate h3(15) free hi if h1 is in memory, free it. //if not do nothing allocate h4(10) allocate h5(30) free h2 allocate h6(30) allocate h7(30) allocate h8(5) free h3 allocate h9(10) When allocating using first-fit, which allocations (h1....9) will fail H5 H7 H8 H9 H5, H9 When allocating using best-fit which allocations (h1....9) will fail H5 H7 H8 H9 H5, H9

Explanation / Answer

To allocate the space dynamically, we have use the unary operator i.e. new, that must be followed by the type being allocated. new int;        new double;     If creating an array dynamically, use the same form, but put brackets with a size after the type: new int[40];      new double[size];                   These above statements are not very useful by themselves, because the allocated spaces have no names! BUT, the new operator returns the starting address of the allocated space, and this address can be stored in a pointer: int * r;        r = new int;   double * d;     d = new double; int x = 60; int * list = new int[y]; float * numbers = new float[y+20];