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

  Impact of technology on customers

The impact of technology on customers in regard to the following: How the company introduced the new product to customers

  Similarities between a lumped and a distributed element

What are the differences and similarities between a lumped element and a distributed element. How many steps are required to design a) an RF circuit? b) A microwave circuit?

  Describe at least one possible effect that multithreading

1Describe at least one (1) possible effect that multithreading could have on event-driven programming when you are either developing or using a computer program. Support your response with at least (1) example of the effect of multithreading.

  Perform in-depth research and provide an explanation

You will perform in-depth research and provide an explanation of how an issue associated with your selected topic relates to the consumption of digital media.

  Write an isr in c to add the signed value on port t (ptt)

Write an ISR, in C, to add the signed value on PORT T (PTT) to the byte value stored in location data1.

  Describe the necessary hardware and software components

Your company wants to create an application that allows employees to dial in from a remote location and using a single connection, access their voice mail, e-mail, and data files. What kind of system would allow this? Describe the necessary hardware ..

  Write a program that places the names in an array

The USPres.txt contains the names of the 44 U.S. presidents in the order in which they served. write a program that places the names in an array and displays all presidents for a requested range of numbers.

  Make databases useful to corporations

Evaluate the tools, technology, and trends that make databases useful to corporations. Provide an example of a corporate database and how your tools and technology would be used in the organization of your choice

  Create a new layer and explore ways to draw

Create a new layer and explore ways to draw and paint using what you learned to ‘posterize' parts of your work by using the Live Trace tool and any other tools you would like

  The task of accessing physical devices

3. The task of accessing physical devices is divided between IO.SYS and MSDOS.SYS. Briefly explain the functions performed by these two modules. Why does it make sense to split these sets of functions ?

  Describe and assess the evaluation method by the testing

Describe and assess the evaluation method being used by the testing company, i.e., nonvisual and verbal recording of browser activities and tester's vocal comments.

  Write and explain briefly three guidelines for sound policy

Write and explain briefly three guidelines for sound policy, as stated by Bergeron and Bérubé. Are policies different from standards? In what way? Are policies different from procedures? In what way?

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