473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
6 2538
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

<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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage...
2
by: Marek Malowidzki | last post by:
Hi all, I am writing a component that exposes a C++ library as a .NET component. The approach is somewhat automatic: every library C++ class has its managed C++ counterpart that keeps a pointer...
10
by: Jakob Bieling | last post by:
Hi, Whenever allocating memory using operator new or operator new I feel like I should only use it very sparingly, because otherwise memory is wasted (by additional overhead needed to manage all...
6
by: MattC | last post by:
I noticed when storing large amounts of information in the StateServer Service that this does not increase in size, the worker process itself seems to grow. I set up a test case to try and prove...
5
by: Grant Mills | last post by:
Is there anyway to reduce the amount of memory a VB.net program allocates? Just a simple windows form, with one button and a label, and all the button does is change the text in the label (it's...
0
by: masri999 | last post by:
When I executed DBCC Memory Status following are the out put Buffer Distribution Stolen 187191 Free 1026 Procedures 6698 Inram 0 Dirty 154661 Kept 0 I/O 0
0
by: TurboFreak | last post by:
Ok all. I have a program I designed that is to simulate three memory manager types and I want to graph the output in realtime in three different group boxes. I have the initial rectangles drawn and I...
6
by: Dave Rahardja | last post by:
I need to design a container that must hold a set of references to a variety of object types, managed by different memory managers. At some time, the container must destroy each object. Currently I...
0
by: Steve Holden | last post by:
Hank @ITGroup wrote: It doesn't really make that much sense to watch memory usage as you have been doing. Your first test case appears to trigger a specific pathology, where the memory allocator...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.