Initiate a compaction of free memory

Assignment Help Basic Computer Science
Reference no: EM13935388

In this exercise, we simulate a memory allocation (we just want to see the effect of fragmentation and of compacting memory fragments into larger ones). For this, we manage a list of memory segments in our program:typedef struct segment { int start ; int size ;int status ; struct segment * next ;} segment_t ;The above segment descriptor describes a memory segment in terms of its start address, its size and whether it is ALLOCATED or FREE. This descriptor is part of a list (contains a pointer to next segment descriptor).

Initially, there is only one segment with status == FREE, describing the complete memory as one segment.Two functions have to be implemented: mem_alloc() and mem_free(). With mem_alloc(), a junk of memory is allocated: it takes as a parameer the size of memory required and returns a pointer to the segment created or NULL, if not enough free memory can be found.

With mem_free(), a segment can be freed up again. If there are two free segments adjacent to each other, they have to be combined into one segment (one of the segment nodes has to be removed from the list).The prototype for mem_alloc(): segment_t * mem_alloc( int size ) A pointer to the allocated segment is returned.The prototype for mem_free(): void mem_free ( segment_t * segment ) It takes the segment to be freed as a parameter.Over time, the memory will become fragmented and a call to mem_alloc() will fail, as no free segment large enough may be available.

The function mem_alloc() therefore has to initiate a compaction of free memory : all allocated segments should be moved towards the top of the list and all free segments to the bottom of the list. When all free segments are collected in one place, they all should be replaced by one single segment descriptor describing one free memory segment.Test mem_alloc() and mem_free(). mem_alloc() takes a size of memory as a parameter and returns a pointer to the allocated memory segment. This pointer to the allocated segment has to be recorded in your test environment (create a list).

You can implement a little menu that runs in an endless loop and lets you allocate memory. If you want to free memory from this menu, you need an extra command that lets you first list the allocated segments, so that you can select one of them to be freed.Hints for implementation:

Implement your application in the form of three files: start with memalloc.h, in which you specify the segment structure and extra parameters such as the maximum size of the memory and the function prototypes. Continue with memalloc.c, that includes this header file and implements the two functions mem_alloc() and mem_free(). Create a third file memtest.c that includes the header file andimplements the main() function of your programHere is a first go at the memalloc.h#ifndef MEMALLOC_H#define MEMALLOC_H#define MAXMEMORY 1024typedef struct segment { int start ; int size ; int status ; struct segment * next ;} segment_t ;segment_t * mem_alloc ( int ) ;void mem_free( segment_t * ) ;

Reference no: EM13935388

Questions Cloud

Designing and prototyping a network : You are tasked with designing and prototyping a network for example.com, a national electronics retailer. Example.com currently has four regional stores (Nth, Sth, Eas, Wes) but has plans to expand as finances and their customer base permits.
Calculate the surface areas and volumes : Calculate the surface areas and volumes of both of these cells then calculate the sa/v for each of them. The SA, V and Sa/V dived out of each of theses cells. which one of these would be most efficeint at feeding itself?
Critical review of the current market for online education : Your task is to provide a critical review of the current market for online education as well as providing an overview and definition of what online education is and how it works.
What would your initial diagnostic evaluation include : George is a 59-year-old African American lawyer who experienced weakness and numbness of his right side while playing golf this morning. What would your initial diagnostic evaluation include? What are the differential diagnoses
Initiate a compaction of free memory : In this exercise, we simulate a memory allocation (we just want to see the effect of fragmentation and of compacting memory fragments into larger ones). For this, we manage a list of memory segments in our program:typedef struct segment { int star..
What effect of exposure on cranial skeleton of salamander : During early development, a snake embryo was exposed to a toxin that interferes with normal migration and differentiation of mesoderm. Name the major structures of the integument most affected by this exposure and how each structure is affected.
Role of training and development : Explain the role of training and development in meeting the organization's strategic objectives. Describe different employee training and development methods and their advantages and disadvantages.
Managing information and technology : Students are required to produce an assessment of the role that Information system plays in organisations in their pursuit of gaining competitive advantage.
Determine the normal forces applied to the installed stud : The tool shown is used for straightening twisted members as wooden framing is completed. If the force P = 30 lb is applied to the handle as shown, determine the normal forces applied to the installed stud at points A and B. Ignore friction.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Design concept in terms of the usability of the design

A justification for the design concept in terms of the usability of the design. You should explain why your decisions make sense and why your interface concept works for the application. Any preliminary designs can be included as an Appendix to th..

  What is the significance of using the access modifier

What is the significance of using the access modifier private with instance variables?

  What is the difference between coupling and cohesion

What is the difference between coupling and cohesion? Which should be minimized and which should be maximized and what complications are imposed if one tries to implement a dynamic list using a traditional homogeneous array?

  Write some code that swaps their values

Given two int variables, firstPlaceWinner and secondPlaceWinner , write some code that swaps their values. Declare any additional variables as necessary.

  Determine slas are necessary and identify monitoring points

Determine if internal service-level agreements (SLAs) are necessary, and identify the monitoring points and levels for an SLA

  Provide a site map of your e-commerce website

Provide a site map of your e-commerce website in the form of a tree diagram that shows hierarchical structure of your e-commerce website

  Write an sql query (mysql)

Guest (guestNO, guestName, guestAddress) Question:  How do I write an SQL Query (mysql) that would give me  "the average number of bookings for each type of room?"

  Compare and contrast the major microeconomic failures

Essay Topic: Compare and contrast the major microeconomic failures and macroeconomic failures that you learned this semester.To get you started concentrate on two distinct chapters in the Schiller textbook. See chapter 4 for an analysis of the prob..

  Change arp entry in computer for mac address

Print your ARP cache table. Find a server on your local network. Change its ARP entry in your computer to point to your computer's MAC address. Print new ARP cache table. Now use the service and see what happens.

  Task in artifial intellegince technique

Task in Artifial Intellegince technique - Emplyee Ant colony optimization for classifying KDD99 data set into its classes

  What makes an effective erp system?

What makes an effective ERP system?

  Write an isr in c to add the signed value on port t (ptt)

Write an ISR, in C, to add the signed value on PORT T (PTT) to the byte value stored in location data1.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd