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

  What is a manipulator? give an example.

What is a Manipulator? Give an example.

  About specialized functions

Specialized Functions

  Process of managing system projects

For this unit, you will be analyzing the business case and learning about the process of managing system projects. You will become familiar with the SCR case study involving the new TIMS system and your very important role! Be sure to read through..

  Design and implement a graphical user interface

Design and implement a graphical user interface (GUI) that let user draw geometrical object such as rectangles, circles. squares, and triangles. Create UML class diagram for your classes. Add JavaDoc comments to your classes.

  Write a complete program that will open a file

write a complete program that will open a file called numbers.txt that contains only integers separated by some white space characters. Your program should add up all of the numbers and print out the sum and the average of all the integers in the ..

  Design a database application to keep track of movies

Design a database application to keep track of movies, actors, and the roles played by actors in movies. You may make up all the data.

  Prepare gross pay and net pay functions for valid user name

Prepare gross pay and net pay functions, and give user input validation to check for valid user name. Hours worked is between 0 and 80 hours, and hourly wage is between $8.95 and $50.

  Performs encryption

Performs encryption

  Write a program that asks the user to respond to a question

Write a program that asks the user to respond to a question by entering either 1 for yes or 2 for no.

  Write a function that displays the prompt string

Write a function that displays the prompt string, followed by a space, reads a floating point number in, and returns it.

  Describing use of request for information

Describe in scholarly detail how you would utilize RFI (Request For Information) procedures to recognize potential vendors in the acquisition process, and RFQ.

  Write a class named candy

Write a constructor that takes arguments for the candy's name, it's calories per serving, whether it contains peanuts, and it's sourness.

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