1. Homepage
  2. Programming
  3. 159.342 - Operating Systems and Networks Assignment #3: Memory Management Using the Buddy System Strategy

159.342 - Operating Systems and Networks Assignment #3: Memory Management Using the Buddy System Strategy

Engage in a Conversation
New ZealandMassey University159.342159342Operating Systems and NetworksMemory Management Using the Buddy System StrategyCC++Malloc

159.342 - Operating Systems and Networks CourseNana.COM

Assignment #3  (due on 11/Jun) CourseNana.COM

Memory Management Using the Buddy System Strategy CourseNana.COM

  CourseNana.COM

OBJECTIVE: CourseNana.COM

The main objective in this assignment is to implement the Buddy System memory management strategy by writing two functions that implement the same functionalities as the C Standard library’s malloc() and free().   You should apply your knowledge of memory management concepts, so the functions are as efficient as possible.  The buddy system will be characterised and compared against the existing C Standard library functions based on ACTUAL RUNNING TIME and MEMORY USAGE.    CourseNana.COM

Given a large block of contiguous memory to manage, your functions should be able to fulfil a series of memory allocation and deallocation requests.  In your implementation, you are not allowed to use the built-in malloc, free, new, delete or any other memory allocators that come from other third-party libraries. CourseNana.COM

START-UP CODES: CourseNana.COM

The start-up codes provide a test routine that makes successive calls for memory allocations and deallocations, involving a replaceable implementation of MALLOC and FREE.  Functions for measuring the actual running time and total memory usage of the memory management strategy are also provided. CourseNana.COM

/////////////////////////////// CourseNana.COM

// TEST ROUTINE CourseNana.COM

/////////////////////////////// CourseNana.COM

#ifdef RUN_COMPLETE_TEST  CourseNana.COM

   cout << "\n\n executing " << NO_OF_ITERATIONS << " rounds of combinations of memory allocation and deallocation..." << endl; CourseNana.COM

    CourseNana.COM

   for(i=0;i<NO_OF_ITERATIONS;i++) { CourseNana.COM

  CourseNana.COM

      k=myrand() % NO_OF_POINTERS; // pick a pointer CourseNana.COM

  CourseNana.COM

      if(n[k]) { // if it was allocated then free it CourseNana.COM

         // check that the stuff we wrote has not changed CourseNana.COM

         if ( (n[k][0]) != (unsigned char) k)//(n[k]+s[k]+k) ) CourseNana.COM

            printf("Error when checking first byte! in block %d \n",k); CourseNana.COM

         if(s[k]>1 && (n[k][s[k]-1])!=(unsigned char) k )//(n[k]-s[k]-k)) CourseNana.COM

            printf("Error when checking last byte! in block %d \n",k); CourseNana.COM

  CourseNana.COM

         FREE(n[k]);         CourseNana.COM

      } CourseNana.COM

      size=randomsize(); // pick a random size CourseNana.COM

      #ifdef DEBUG_MODE CourseNana.COM

        cout << "\tPick random size to allocate: " << size << endl; CourseNana.COM

      #endif CourseNana.COM

        CourseNana.COM

      n[k]=(unsigned char *)MALLOC(size); // do the allocation CourseNana.COM

      if(n[k] != NULL){ CourseNana.COM

         #ifdef DEBUG_MODE CourseNana.COM

            cout << "\tallocated memory of size: " << size << endl;   CourseNana.COM

         #endif   CourseNana.COM

         s[k]=size; // remember the size CourseNana.COM

         n[k][0]=(unsigned char) k;  // put some data in the first and CourseNana.COM

  CourseNana.COM

         if(s[k]>1) n[k][s[k]-1]=(unsigned char) k; // last byte CourseNana.COM

  CourseNana.COM

      } else { CourseNana.COM

         cout << "\tFailed to allocate memory of size: " << size << endl;   CourseNana.COM

      }        CourseNana.COM

   } CourseNana.COM

#endif CourseNana.COM

You can switch between different memory management strategies by changing the definition of MALLOC and FREE, as defined inside main.cpp (see below).  The first two options are already provided, but the third option corresponds to the Buddy System and therefore, needs to be implemented in this assignment: CourseNana.COM

//--------------------------------------- CourseNana.COM

// WHICH MEMORY MANAGEMENT STRATEGY? CourseNana.COM

//--------------------------------------- CourseNana.COM

// enable the following compiler directives to test the real malloc and free CourseNana.COM

//(1) use built-in C functions CourseNana.COM

const string strategy = "malloc"; CourseNana.COM

#define MALLOC malloc CourseNana.COM

#define FREE free CourseNana.COM

  CourseNana.COM

//--------------------------------------- CourseNana.COM

//enable the following compiler directives to test a simple implementation of malloc and free CourseNana.COM

//(2) use user-defined functions CourseNana.COM

//const string strategy = "mymalloc"; CourseNana.COM

// #define MALLOC mymalloc CourseNana.COM

// #define FREE myfree CourseNana.COM

  CourseNana.COM

//--------------------------------------- CourseNana.COM

//enable the following compiler directives to test your implementation of the Buddy system strategy CourseNana.COM

//(3) use Buddy System CourseNana.COM

// const string strategy = "Buddy System"; CourseNana.COM

// #define USE_BUDDY_SYSTEM CourseNana.COM

// #define MALLOC buddyMalloc CourseNana.COM

// #define FREE buddyFree CourseNana.COM

//--------------------------------------- CourseNana.COM

  CourseNana.COM

CORE FUNCTIONS REQUIRED: CourseNana.COM

Skeleton functions for buddy system’s malloc and free are already provided inside buddysys.cpp.  Write your implementation inside them.  You are allowed to add any supporting functions, data structures and variables in the program.    CourseNana.COM

void *buddyMalloc(int request_memory){ CourseNana.COM

  //write your buddy system’s memory allocation codes here CourseNana.COM

  //this function should provide the same functionality as the malloc() function CourseNana.COM

} CourseNana.COM

int buddyFree(void *p){ CourseNana.COM

  //write your buddy system’s memory deallocation codes here CourseNana.COM

  //this function should provide the same functionality as the free() function CourseNana.COM

} CourseNana.COM

AUXILIARY FUNCTIONS PROVIDED: CourseNana.COM

The Auxiliary functions, constants and data structures declared and implemented inside auxiliary.cpp and auxiliary.h should all be kept as is. CourseNana.COM

  CourseNana.COM

MINIMUM CONTIGUOUS MEMORY SIZE CourseNana.COM

As part of characterising the performance of your implementation, find the minimum contiguous memory size that allows the Buddy System strategy to accommodate the succession of memory allocation and deallocation requests in the test routine.  To accomplish this, you need to experiment with different settings for the NUMBEROFPAGES until the test routine could be fully completed.  CourseNana.COM

Example:    CourseNana.COM

As an example, if you set NUMBEROFPAGES equal to 1024, then the MEMORYSIZE could be computed as follows: CourseNana.COM

// inside main.cpp CourseNana.COM

MEMORYSIZE = (long long int) ((long long int)NUMBEROFPAGES * (long long int)PAGESIZE); CourseNana.COM

  CourseNana.COM

Note that in the start-up codes, the PAGESIZE is set to 4096.  Therefore, MEMORYSIZE will be equal to 4,194,304 bytes (1024 * 4096) or 4.19 MegaBytes CourseNana.COM

Next, with your MEMORYSIZE setting, run the test routines to see if all requests for memory allocations and deallocations can be satisfied.  If not, increase the MEMORYSIZE. CourseNana.COM

  CourseNana.COM

Table 1. MEASURE OF PERFORMANCE CourseNana.COM

Characterise your Buddy System’s implementation and compare it against the C Standard library’s malloc and free by filling-up the following table. CourseNana.COM

BUDDY SYSTEM STRATEGY CourseNana.COM

Characteristic CourseNana.COM

  CourseNana.COM

Unit CourseNana.COM

MINIMUM NUMBEROFPAGES CourseNana.COM

  CourseNana.COM

Pages CourseNana.COM

MINIMUM MEMORY SIZE CourseNana.COM

  CourseNana.COM

MegaBytes CourseNana.COM

RUNNING TIME CourseNana.COM

  CourseNana.COM

MicroSeconds CourseNana.COM

C Standard Library’s malloc and free CourseNana.COM

Characteristic CourseNana.COM

  CourseNana.COM

Unit CourseNana.COM

MINIMUM NUMBEROFPAGES CourseNana.COM

  CourseNana.COM

Pages CourseNana.COM

MINIMUM MEMORY SIZE CourseNana.COM

  CourseNana.COM

MegaBytes CourseNana.COM

RUNNING TIME CourseNana.COM

  CourseNana.COM

MicroSeconds CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Other Notes

0 – zip all the files comprising your codes by compressing the entire folder.  The structure of the folder and subfolders should be exactly the same as that of the start-up codes given. CourseNana.COM

1 - Submit your files electronically via Stream.  You should submit the complete set of files, required to compile your codes, including the makefile, Measure of Performance (Table 1) Checklist (see Table 2) and snapshots of simulation results.  Bundle all your files together in a *.zip file. CourseNana.COM

2 - This assignment is worth 15 marks. CourseNana.COM

3 - Marks will be subtracted for obvious copying and/or for delays without justification. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

QQ QQ
Wechat WeChat
Whatsapp Whatsapp
New Zealand代写,Massey University代写,159.342代写,159342代写,Operating Systems and Networks代写,Memory Management Using the Buddy System Strategy代写,C代写,C++代写,Malloc代写,New Zealand代编,Massey University代编,159.342代编,159342代编,Operating Systems and Networks代编,Memory Management Using the Buddy System Strategy代编,C代编,C++代编,Malloc代编,New Zealand代考,Massey University代考,159.342代考,159342代考,Operating Systems and Networks代考,Memory Management Using the Buddy System Strategy代考,C代考,C++代考,Malloc代考,New Zealandhelp,Massey Universityhelp,159.342help,159342help,Operating Systems and Networkshelp,Memory Management Using the Buddy System Strategyhelp,Chelp,C++help,Mallochelp,New Zealand作业代写,Massey University作业代写,159.342作业代写,159342作业代写,Operating Systems and Networks作业代写,Memory Management Using the Buddy System Strategy作业代写,C作业代写,C++作业代写,Malloc作业代写,New Zealand编程代写,Massey University编程代写,159.342编程代写,159342编程代写,Operating Systems and Networks编程代写,Memory Management Using the Buddy System Strategy编程代写,C编程代写,C++编程代写,Malloc编程代写,New Zealandprogramming help,Massey Universityprogramming help,159.342programming help,159342programming help,Operating Systems and Networksprogramming help,Memory Management Using the Buddy System Strategyprogramming help,Cprogramming help,C++programming help,Mallocprogramming help,New Zealandassignment help,Massey Universityassignment help,159.342assignment help,159342assignment help,Operating Systems and Networksassignment help,Memory Management Using the Buddy System Strategyassignment help,Cassignment help,C++assignment help,Mallocassignment help,New Zealandsolution,Massey Universitysolution,159.342solution,159342solution,Operating Systems and Networkssolution,Memory Management Using the Buddy System Strategysolution,Csolution,C++solution,Mallocsolution,