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

  According to the study by cole and ohanion

According to the study by Cole and Ohanion, which of the following is an explanation for why the Depression lasted from 1936-1943?A) The National Relations Act weakened unions and let nominal wages fall.B) The government did not sufficiently increase..

  Consider three lans interconnected by two routers

Consider three LANs interconnected by two routers as shown in Figure below. Assign IP addresses to all of the interfaces. For Subnet 1 use addresses of the form 192.168.1.xxx; for Subnet 2 use addresses of the form 192.168.2.xxx; and for Subnet..

  Write a program to perform grocery check-out procedure

Write a program to perform grocery check-out procedure for a simple store. Use a dynamic array of structures (Up to 100) to store this information. For each product we store the following information.

  One approach to system development

One approach to system development that Reliable might take is to start one large project

  Using positive edge triggered t

Using positive edge triggered T flip flops, show the design of a modulo 7 asynchronous counter that counts 0,1...6,0, etc. You may assume that your flip flop

  Corporate embezzlement

Imagine you are employed by a large city police department as the leader of the digital forensics division. A large corporation in the city has contacted the police for assistance in investigating its concerns that the company Chief Financial Offi..

  Explain how to structure worksheet including titles

Explain how you will structure the worksheet, including the titles, column headings, and formulas to calculate the time it takes to make each size of cage.

  Propose the dfs components that you would consider implement

Suppose you are employed by a company that has recently acquired another multinational company operating in three (3) different countries. One (1) of your managers has asked whether or not it would be feasible to replicate data between these differen..

  Create the following for bet charts

The Banking e-Teller system allows bank customers to perform ATM transactions from their cell or smart phones. BET will allow customers to check balances, make remote photo capture check deposits, and perform balance transfers to their checking or..

  Choose an information system for an individual project

Choose an information system for an individual project.

  Write a program that uses a recursive method

A palindome is a string that reads the same both forward and backward. For example,the string "madam" is a palindrome. write a program that uses a recursive method to check whether a string is a palindome.

  Short notes on web applications attack

The Software Development Director has asked you to provide a detailed presentation for her department regarding the most common Web application threats and the manner in which their products could compromise customer financial data.

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