473,756 Members | 5,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Whenev er, 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 2565
CA*********@gma il.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.Whenev er, 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*********@gm ail.comwrote in message
news:20******** *************** ***********@j78 g2000hsd.google groups.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.Whenev er, 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*********@gma il.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.Whenev er, 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*******@rocke tmail.com
Jan 7 '08 #4
On Jan 7, 1:46 pm, CANCER.0...@gma il.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.Whenev er, 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...@nurfuersp am.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
13009
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 reported through task manager peaks between 41-42MB. I've stopped and restarted the MSSQLserver service and checked that the running values are what I set them to be. Does anybody have any ideas as to why the sqlservr.exe would be utilizing more...
2
1954
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 to the unmanaged class instance. As usually in such a scenario, the IDisposable/Dispose()/Dispose(bool) pattern should be used. The problem is that in my approach it is often impractical, as the library's unmanaged objects are quite small and
10
1860
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 those allocations) which also loses some performance. I am specifically talking about many little allocations (approx. 16-512 bytes). Is my feeling about this justified? thanks! --
6
3655
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 this, I placed a button on a web form that ran the foloowing code. string temp = "index"; for(int i = 0; i < 1000000; i++) {
5
6739
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 even hardcoded) and the EXE is using 15000+k of memory according to the task manager... I mean I realize that VB is going to be more bloated than a C++ app. But is
0
4223
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
1043
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 have code to populate the red rectangle overlays in my groupbox_paint call BUT I need to know how do I access this from another subroutine? ' '///Draw initial Rectangles in Group Boxes/// Private Sub grpBestFit_Paint(ByVal sender As Object,...
6
2130
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 have the following design in mind: class Destructible // interface { public: virtual void destroy() = 0;
0
150
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 actually returns the memory to the operating system when the garbage collector manages to free all of it. Most often this doesn't happen - a chunk of memory might be 99.99% free but still have one small piece used, and so while there is a large...
0
9462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.