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

Needed C/C++ code for memory manager with following reqirements

P: n/a
The problem statement is as follows

Create a library that creates pools of memory of different sizes.For
e.g. one pool of 32 byte size, another pool of 64 byte size and so
on.Create an array of pointers and store the pointer to each pool in
this array.Each pool maintains one link list of free pointers and
another link list of allocated pointers.Whenever, the main program
requests for a memeory of say, size 32 bytes, a pointer is returned
from the free list of 32-byte pool and that pointer is moved to
allocated list.Whenever the main program requests for freeing this
memory, the pointer will be returned back to the 32 byte size free
pool.Write both the memory manager and main program that uses it.
Jan 7 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
CA*********@gmail.com wrote:
The problem statement is as follows

Create a library that creates pools of memory of different sizes.For
e.g. one pool of 32 byte size, another pool of 64 byte size and so
on.Create an array of pointers and store the pointer to each pool in
this array.Each pool maintains one link list of free pointers and
another link list of allocated pointers.Whenever, the main program
requests for a memeory of say, size 32 bytes, a pointer is returned
from the free list of 32-byte pool and that pointer is moved to
allocated list.Whenever the main program requests for freeing this
memory, the pointer will be returned back to the 32 byte size free
pool.Write both the memory manager and main program that uses it.
See FAQ 5.2

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #2

P: n/a

<CA*********@gmail.comwrote in message
news:20**********************************@j78g2000 hsd.googlegroups.com...
The problem statement is as follows

Create a library
It says "create a library", not "get someone to do it for you".
that creates pools of memory of different sizes.For
e.g. one pool of 32 byte size, another pool of 64 byte size and so
on.Create an array of pointers and store the pointer to each pool in
this array.Each pool maintains one link list of free pointers and
another link list of allocated pointers.Whenever, the main program
requests for a memeory of say, size 32 bytes, a pointer is returned
from the free list of 32-byte pool and that pointer is moved to
allocated list.Whenever the main program requests for freeing this
memory, the pointer will be returned back to the 32 byte size free
pool.
Write both the memory manager and main program that uses it.
It says "Write the memory manager and the program", not
"get someone to do it for you."

How are you going to learn if you don't do the work?

If you show us evidence of your efforts (e.g. *your* code),
and ask specific questions, we'll be glad to help. But
nobody's going to do your work for you.

-Mike
Jan 7 '08 #3

P: n/a
CA*********@gmail.com wrote:
The problem statement is as follows

Create a library that creates pools of memory of different sizes.For
e.g. one pool of 32 byte size, another pool of 64 byte size and so
on.Create an array of pointers and store the pointer to each pool in
this array.Each pool maintains one link list of free pointers and
another link list of allocated pointers.Whenever, the main program
requests for a memeory of say, size 32 bytes, a pointer is returned
from the free list of 32-byte pool and that pointer is moved to
allocated list.Whenever the main program requests for freeing this
memory, the pointer will be returned back to the 32 byte size free
pool.Write both the memory manager and main program that uses it.
We will not do your homework for you. Then you would not learn.

So, try writing it. Take it a step at a time.

First do step one.
Create a library that creates pools of memory of different sizes.

So how would you do that? Well, you would need pointers to the memory, and
need to allocate the memory with either new or malloc. Do you know how to
allocate memory? Have you ever used new before? If not, read your text
book.

Once you manage to get a pointer that points to allocated memory go to step
2.
Create an array of pointers and store the pointer to each pool in this
array.

Do you know what an array is? Do you know how to create one? You would
need to create an array of pointers.

Now step three.
Each pool maintains one link list of free pointers and another link list of
allocated pointers.

I *think* that the link list would point to the elements in your array of
pointers. I.E. 0 for element 0 of the array (first one), 1 for the 2nd,
etc... Create the linked lists Test them.

Now do step four.
Whenever, the main program requests for a memeory of say, size 32 bytes, a
pointer is returned from the free list of 32-byte pool and that pointer is
moved to allocated list.

Write an interface for that.

And finally do step 5 and your done.
Write both the memory manager and main program that uses it.

Just write a program that uses your linked list.

Do it one step at a time, read your textbook on things you don't remember
how to do or things you slept through in the class.

When you get stuck, show your code, what you are trying to do, what is not
working, and we will help you.

--
Jim Langston
ta*******@rocketmail.com
Jan 7 '08 #4

P: n/a
On Jan 7, 1:46 pm, CANCER.0...@gmail.com wrote:
The problem statement is as follows

Create a library that creates pools of memory of different sizes.For
e.g. one pool of 32 byte size, another pool of 64 byte size and so
on.Create an array of pointers and store the pointer to each pool in
this array.Each pool maintains one link list of free pointers and
another link list of allocated pointers.Whenever, the main program
requests for a memeory of say, size 32 bytes, a pointer is returned
from the free list of 32-byte pool and that pointer is moved to
allocated list.Whenever the main program requests for freeing this
memory, the pointer will be returned back to the 32 byte size free
pool.Write both the memory manager and main program that uses it.

Wow, thats a lovely specification. What have you got so far?
Whats that? You don't know where to start?
Here you go:

int main()
{
}
Jan 7 '08 #5

P: n/a
Jim Langston wrote:
[ a lot of advice ]
Wow. Jim, you definitely got too much time on your hands ;) I wouldn't
spend a minute responding to a lazy git like this one...

Regards,

Lars
Jan 8 '08 #6

P: n/a
On Jan 8, 3:05 am, Lars Uffmann <a...@nurfuerspam.dewrote:
Jim Langston wrote:
[ a lot of advice ]

Wow. Jim, you definitely got too much time on your hands ;) I wouldn't
spend a minute responding to a lazy git like this one...

Regards,

Lars

Fortunately, this newsgroup nor this thread is for the lazy one. Its
for everyone's benefit.
I though his procedure of steps was quite well laid out, although i
would do the whole project without using a single naked pointer (just
for kicks).
If the OP prefers being bored than having fun... his loss.

That teacher should get hell for specifying # of bytes in his
specification.
Thats exactly what a programmer should not be doing.
Its not realistic, does not reflect real world problems and encourages
bad habits (programming the implementation, not the language). Some of
you might disagree.

Could always just allocate unsigned chars perhaps.
std::vector< unsigned char v32(32);
std::vector< unsigned char v64(64);
or
std::bitset bs32[256]; // hehe, drive teacher mad

and store those in a container with 2 std::lists per allocation-size
of the above, one free store, one allocated store each.
Its a simple project really.
Jan 8 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.