Descriptor describes a memory segment

Assignment Help Basic Computer Science
Reference no: EM13935857

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 segmengmentation 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 segment large enough may be available. Thefunction 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

Reference no: EM13935857

Questions Cloud

Describe a statistical test for the ife : Describe a statistical test for the IFE. Would the IFE be more likely to hold between the United Kingdom and Hungary if trade barriers were completely removed.
Choose one exceptional world leader living or dead : Choose one exceptional world leader living or dead, good or bad, past or present. Leaders may be Presidents, Prime Ministers, Inspirational, Religious, Courageous, Artistic, Scientific, Brave, Movie Stars, CEO's, Managers, Athletes but they don't ..
Given the churn data for training and test : Given the churn data for training and test, develop models using different techniques i.e. "Logistic Regression", "Decision Trees", "Random Forests" and "Neural Networks".
Why is the synthesis of mrna a central issue for all viruses : How can several proteins be made from the above nucleic acid (ie you only saw 1 long piece). What does this imply about the activity of at least one of the proteins that are synthesized?
Descriptor describes a memory segment : 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..
Leadership styles in management : Research the many leadership styles in management. Select one style and write a report that describes the positive and negative attributes of the leadership style and how you identify with it.
How can you prevent or slow down the spread : Describe 1-2 of the things that people do (you can include individuals, doctors, health care professionals, hospitals, farmers, etc.) that contribute to this problem? Why?
Calculate estimated break-even point in annual unit sales : Martinez Company has decided to introduce a new product. The new product can be manufactured by either a capital-intensive method or a labor-intensive method. Calculate the estimated break-even point in annual unit sales of the new product if Marti..
Compare the most appropriate hedge to an unhedged strategy : Then, compare the most appropriate hedge to an unhedged strategy, and decide whether Black Rod should hedge its payables position.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Deadlock prevention

In  deadlock prevention , we constrain resource requests to prevent at least one of the four conditions of deadlock (Mutual exclusion, Hold and wait, No preemption, Circular wait). This is either done indirectly, by preventing one of the three necess..

  Discuss its effect on attributes, entities, and relationshi

Given the business rule "an employee may have many degrees," discuss its effect on attributes, entities, and relationships.

  Demonstrate method polymorphism

Write some usable code snippets that demonstrate method polymorphism.

  String s of lowercase english letters

Given a string S of lowercase English letters, write a program to find the longest magic string than can be obtained by removing some letters of S. If there are more than one solutions, choose the longest magic string which is lexicographically small..

  Write a java program that declares an array alpha

Initialize the array so that the first 25 elements of array are equal to the square of the index variable, and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed on the conso..

  Signature-based intrusion detection can identify previously

The primary difference between network-based IDS and IPS is that an IPS responds to suspected attacks by blocking network traffic, while an IDS only provides notification that suspicious traffic is observed

  Drivers for digital dashboards found in automobiles

Believe or not digital dashboards can be found in automobiles. In fact, Mossberg (2010) wrote article titled, "Ford Drives Digital Dashboards to Next Level. Are drivers ready for this kind of technology?

  Power point presentation on data warehouse tasks

Ppt data warehouse tasks: First Style  1-Dimensions 2- The fact table 3- Browse the cube

  Write a program that will read in a length in meters

Write a program that will read in a length in meters and centimeters and output the equivalent length in feet and inches. Use at least three functions; one for input, one or more for calculating and one for output.

  Find the error in the following pseudocode

Find the error in the following pseudocode

  Compare and contrast the in terms of cores/microprocessors

Compare and contrast the following, in terms of cores (or microprocessors), random access memory (RAM), disk storage, and networking capabilities.

  Science and technology

Many people and experts feel that there is a strong link and dependency between science and technology. It is arguable that one can exist without the other. Explain in detail and provide your perspective with practical examples of why you feel there ..

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