Memory segment in terms of its start address

Assignment Help Basic Computer Science
Reference no: EM13936865

If you feel that your knowledge about the programming language C is insufficient, please go through this following online course first:
• C Tutorial

Further information about C is available here:
• C and C++ in 5 days
• https://www2.its.strath.ac.uk/courses/c/

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 parameter 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 struct 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 and implements the main() function of your program Here is a first go at the memalloc.h
#ifndef MEMALLOC_H
#define MEMALLOC_H
#define MAXMEMORY 1024
typedef 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: EM13936865

Questions Cloud

Description of the injury-related public health problem : Description of the injury-related public health problem you selected. Include incidence rates for this problem in the country or community you selected and a description of populations at risk for it
What is map distance between the loci : An individual with Turner's syndrome and afflicted with the X-linked recessive trait nystagmus is produced by parents that are both phenotypically normal. The individual has a brother that is also afflicted with nystagmus and a brother that is phe..
Implement a calculator using stacks and queues. : You will implement a calculator using stacks and queues. Your calculator must support the following operators:
Research requirement : Analysis and the firm along with  supporting charts, graphs and other documentation.  This is not your run of the mill term paper. Depending upon your premise a certain amount of ratio trend analysis must also be performed as well as the integration ..
Memory segment in terms of its start address : 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 se..
Calculate keep-kools total ordering and carrying costs : Calculate Keep-Kool's total ordering and carrying costs using EOQ. Assume that demand is uniform throughout the year and is known with certainty.
Concepts of sct to an environmental health behavior : For this Discussion, you apply the concepts of SCT to an environmental health behavior. You may choose one of these examples or your own topic: recycling; responsible energy use (e.g., compact fluorescent [CFL]/light-emitting diode [LED] lightbulb..
Briefly described the product purchased : 1) Briefly described the product purchased. For example, what was the model, any special features, exact cost, etc.
Design and run a program that takes a numerical score : In this program, create two void functions titled getScore and printGrade with an int argument. The function getScore should have a Reference parameter and printGrade should have a Value parameter.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Give a polynomial-time algorithm for the following problem

Give a polynomial-time algorithm for the following problem. We are given a binary tree T = (V, E) with an even number of nodes, and a nonnegative weight on each edge.

  The average degree for vertices distributed uniformly

Given the number of vertices n and the target expectation d of the average degree for vertices distributed uniformly on the surface of the unit radius sphere, determine a formula for the threshold r such that a random geometric graph on a spher..

  Create a console-based program and a gui application

create a console-based program and a GUI application, which justifies the following conditions: The Main() method prompts the user for an integer value and, in turn, passes the value to a method that squares the number and a method that cubes the ..

  What are the four parts of the compiling process

Flip over this test. On the back of this test write your name in the upper, left-hand corner. What are the four parts of the compiling process

  What are local and global variables

What are local and Global variables? And how many input variables can a MATLAB function have ?

  Led paybyphone to switch to an ip-based network

What are the reasons that led PayByPhone to switch to an IP-based network?

  Explain what type of ospf link state is advertised

Explain what type of OSPF link state is advertised in each of the following cases: i. A router needs to advertise the existence of another router at the end of a ?point-to-point link. ? ii. A router needs to advertise the existence of two stub networ..

  Write and test a version of selection sort for linked lists

Write and test a version of selection sort for linked lists. Write a program to test insertion sort for linked lists.

  Describe the web-based information technologies

Describe the Web-based information technologies

  Convert the binary numbers to their decimal equivalents

Directions: Convert the following binary numbers to their decimal equivalents.

  Which of these conditions returns true

Which of these conditions returns true? Check the Java documentation for the inheritance patterns.

  Code adds two numbers

Study the following Python code. This code adds two numbers. Then increments each number by 1 and displays the result: (input("Enter the value for x:"))

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