By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

i need to create C program. Any one have Code

P: n/a

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
--
Posted via http://dbforums.com
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 19 Sep 2003 09:27:27 -0400, aj902 <me*********@dbforums.com>
wrote:

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.

Nov 13 '05 #2

P: n/a

"aj902" <me*********@dbforums.com> schrieb im Newsbeitrag
news:33****************@dbforums.com...

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
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.