i need to create C program. Any one have Code

A

aj902

Hello ,

I am trying to create a program

where all detail,



http://www.albany.edu/~csi333/projects.htm



in short hand. I need to create four command



a allocate at give size

d deallocate from starting, and size

s staticical of free and min, man free blocks

q quit



i need this program until 24th anyone help me out
 
N

Nick Austin

Hello ,

I am trying to create a program

where all detail,



http://www.albany.edu/~csi333/projects.htm

Nice try. However you obviously didn't read this page because
there is not enough information to complete your class assignment.

"The necessary information about dynamic memory allocation
and the best fit strategy will be presented in the lecture."

"A data structure for maintaining information about free
blocks will be discussed in class."

"You must follow the programming and documentation guidelines
indicated in a previous handout."

Nick.
 
R

Robert Stankowic

aj902 said:
Hello ,

I am trying to create a program

where all detail,



http://www.albany.edu/~csi333/projects.htm



in short hand. I need to create four command



a allocate at give size

d deallocate from starting, and size

s staticical of free and min, man free blocks

q quit



i need this program until 24th anyone help me out

Not with the code, of course, but some hints to get you started:

You have a memory block of 10000 chars at your disposition. From this block
you allocate and deallocate smaller blocks, so after some time your original
block will consist of a mixture of free and allocated pieces...

What information do you need for each piece?
Hint: start address, size, and state(free or allocated)
You may want to put this information into a struct
struct mem_block_t
{
char *start;
size_t size;
int allocated;
};

Now, as the user of your program allocates and deallocates memory, you will
need more of these structs
You will want to make the growing and shrinking of the pool of structs
flexible and easy to handle, so a linked list comes into mind..

extend the struct to:
struct mem_block_t
{
char *start;
size_t size;
int allocated;
struct mem_block_t *next;
};

That's it.
Now all you need are functions to
create a new struct - malloc() is your friend.
insert the new struct and subtract the size of the block which it describes
from the adjacent free space (if any) or remove the struct describing the
adjacent free space if no free space is left. (of course you will also have
to modify the address contained therein)
(you insert by modifying the "next" pointers in the previous and the
new)
remove a struct and add the size of the block which it describes to the
adjacent free space (if any) (of course you will also have to modify the
address contained therein) or create a new struct which describes the
new free block if no free space was adjacent and insert it.
scan the list for free and allocated blocks for the statistics and for
finding the smallest block in which a new request fits (the requirement
that, if there are more blocks of the same size, the block with the
lowest address must be selected does not need any extra work).
and your main menu handler

Now think about how you could test your program and perform the necessary
testing.

Today is the 20th..
plenty of time left to write your code and even come back with questions if
you have problems

HTH
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,207
Latest member
HelenaCani

Latest Threads

Top