Commit 594539a1 by Son Pham

### Lab 9, Problem 2 Completed

parent 3ea40c9e
 ... ... @@ -32,3 +32,26 @@ return (double) totalSize / numBlobs; Since totalSize is always the amount allocated. I only need to take that allocated amount and divided by the numBlobs. Since numBlobs will increase by one everytime an allocation is succeeded, I can just make an int that keep tracks of this number and I don't have to count the number of blobs everytime. [2.1] Think critically about the pseudo-code given. The way the algorithm is currently structued is not typical of programs because: 1. You don't allocate and deallocate like crazy like that, you usually allocate all at once and deallocate all at once. 2. This is not representative of a program fragmentation because when the number of requests are high, you basically chop the program up until everything pieces of very small byte. Usually, a program ALLOCATE ALL MEMORY first and DEALLOCATE ALL MEMORY later. In order to have a representative amount of fragmentation, it is very important to allocate all the memory first and then deallocate later. The pseudo-code for the algorithm would look like. srandom(seed); int r = 0; void *p[num_requests]; int i = 0; while (r < requests): p[r] allocate(random number between 100 and 1000); while (r< requests): if (p[r] != NULL) deallocate(p[r]); average_frag();
 ... ... @@ -27,5 +27,8 @@ while (blob != NULL) { blob = blob -> next; } return (double) totalSize / blobSize; return (double) totalSize / numBlobs; Since totalSize is always the amount allocated. I only need to take that allocated amount and divided by the numBlobs. Since numBlobs will increase by one everytime an allocation is succeeded, I can just make an int that keep tracks of this number and I don't have to count the number of blobs everytime.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!