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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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