Knowledge about the programming language c

Assignment Help Basic Computer Science
Reference no: EM13936854

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: EM13936854

Questions Cloud

Calculate changes costs if he purchases paper from papyrus : Calculate changes costs if he purchases paper from (a) Papyrus and (b) Suffolk Leaves. Which supplier should Manraj choose only on the basis of the financial numbers given in the problem?
Program to modify double linked list : Modify Double Linked List code to include following index based access operations.
Summary of the main points of the article : Find an article on the macro economy (inflation, employment, economic growth). Write a 250 word summary of the main points of the article
Zone of acceptance for a product or category : In what way might deal sites affect the zone of acceptance for a product or category? What are the implications for marketers?
Knowledge about the programming language c : 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..
Do you agree with jules balles range-touts financial control : Do you agree with Jules Ballès, Range-Tout's financial controller, that the supplies purchased from Génie du Bois SA were accounted for improperly? Explain your answer.
Consumer behavior attitude about luxury brands : Looking for a reliable assignment service provide to provide me with an urgent 5 pages report On Consumer behavior attitude about luxury brands.
Write a program using a function and a switch statement : Write a program using a function and a switch statement. The user should be prompted to enter a number in main. The function is called and the number entered is passed to the function. This function parameter will then be used in a switch to disco..
Software tools for managing and analyzing qualitative data : Craft a 3- page paper and 5 references in which you do the following: Compare and contrast software tools for managing and analyzing qualitative data

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Explain what is meant by value type

Explain what is meant by value type and reference type objects in C#. Explain the differences, providing an example of each. Write the code for an example of each. Develop examples.

  Create a legal sales contract for a purchased vehicle

This Application uses Microsoft Word Template to allow a car salesperson to create a legal sales contract for a purchased vehicle and provides a loan calculator to calculate monthly payments for the amount financed.

  Managing information technology projects

1.Describe how organizational culture is related to project management. what type of cultures promote a strong project? 3. Explain the four frames of organizations. how can they help project manager understand the organizational context for their pro..

  What is the use of win32 console functions

What is the use of Win32 Console functions and how they relate and pertain to GUI.

  Is security mechanisms and practices

Organizations around the world often assess their IS security mechanisms and practices by using the Trusted Computer System Evaluation Criteria (TCSEC) or Information Technology Security Evaluation Criteria (ITSEC). The two standards are similar, tho..

  What purposes do cpus, memory and i-o devices

What purposes do CPUs, memory and I-O devices individually serve in a computer system

  Identify a performance problem in a business activity

Identify or select a performance problem in a business activity that you believe could be resolved or substantially improved by the acquisition of IT services performed by a contractor selected in open competition as a result of an RFP

  Identify three different types of analysis models

Identify three different types of analysis models (analytical, simulation-based, and surrogate models) that can be used to represent the weight-holding capacity of the table as a function of the geometrical variables.

  Research on existing or emerging it-related technology

Individual research on existing or emerging IT-related technology and related ethical issues

  Why is rarp used in one case versus arp

Why is RARP used in one case versus ARP? This one is complex and I don't know how to do it

  Compare and contrast monitoring of patient vital signs by

mobile computing has dramatically changed how information is accessed and shared. wireless networking has been an

  Technology and job design

Advancements in technology have certainly made our lives easier over the last twenty years. They've also changed the nature of how many of us do our jobs. A great example is right here in this course...professors can teach from home!

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