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

C

CANCER.0707

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.
 
V

Victor Bazarov

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
 
M

Mike Wahler

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
 
J

Jim Langston

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.
 
S

Salt_Peter

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()
{
}
 
L

Lars Uffmann

Jim said:
[ 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
 
S

Salt_Peter

Jim said:
[ 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.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top