473,809 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

am I running out of memory?

Or just loosing it?

I have a small c++ app which generates millions combinations of bitset
class objects and adds them to a STL map.

(on a side thanks to all who responded to my earlier posting about
increasing the programs speed)

Anyway, I calculate my bitset class object size to be 8 bytes and when
I run this in debug mode I can generate 19,675,656 objects before an
exception is thrown from AfxMem.cpp line 341.

What I don't understand is why I only get that many and not a whole lot
more. 19,675,656 million times 8 is 157,405,208 which is significantly
less than the 1 gig of memory I have running on this machine. I
understand that I don't get the whole gig and thanks to virtual memory
I have 2 gig available but I don't understand why I'm not even getting
close to that mark.

Do you think its truly out of memory or am I trampling on on memory I
shouldn't be. I don't think I am.

One other thing is that I have exception handlers in place but they are
not catching the exception so I'm not sure whats going on there.

Thanks for any help.
Regards

Aug 21 '05 #1
16 3063
Rich S wrote:
Or just loosing it?

I have a small c++ app which generates millions combinations of bitset
class objects and adds them to a STL map.

(on a side thanks to all who responded to my earlier posting about
increasing the programs speed)

Anyway, I calculate my bitset class object size to be 8 bytes and when
I run this in debug mode I can generate 19,675,656 objects before an
exception is thrown from AfxMem.cpp line 341.
I have no idea what 'AfxMem.cpp' is or what is in its like 341. Did
you mean to post it and forgot?
What I don't understand is why I only get that many and not a whole
lot more. 19,675,656 million times 8 is 157,405,208 which is
significantly less than the 1 gig of memory I have running on this
machine. I understand that I don't get the whole gig and thanks to
virtual memory I have 2 gig available but I don't understand why I'm
not even getting close to that mark.
How much overhead does your system produce on top of every object
created in the free store? Perhaps you should try a custom allocator
or something... 19 million objects of the same size are just begging
to be pre-allocated in an array or something.
Do you think its truly out of memory or am I trampling on on memory I
shouldn't be. I don't think I am.
Then who am I to contradict you?
One other thing is that I have exception handlers in place but they
are not catching the exception so I'm not sure whats going on there.


What exception handers? What exception is thrown?

V
Aug 21 '05 #2
Rich S wrote:
Or just loosing it?

I have a small c++ app which generates millions combinations of bitset
class objects and adds them to a STL map.

(on a side thanks to all who responded to my earlier posting about
increasing the programs speed)

Anyway, I calculate my bitset class object size to be 8 bytes and when
I run this in debug mode I can generate 19,675,656 objects before an
exception is thrown from AfxMem.cpp line 341.

What I don't understand is why I only get that many and not a whole lot
more. 19,675,656 million times 8 is 157,405,208 which is significantly
less than the 1 gig of memory I have running on this machine. I
understand that I don't get the whole gig and thanks to virtual memory
I have 2 gig available but I don't understand why I'm not even getting
close to that mark.
Hm, your std::set< T > class very likely is implemented as some kind of
balanced tree, i.e., your objects will be stored as nodes that look
somewhat like this:

struct node {
T data_field;
node* right;
node* left;
node* parent;
some_type balancing_info;
}

Also, keep in mind that the new/delete mechanism is likely to add another
word of memory to keep track of how much memory can be reclaimed at delete.
Thus, depending on how balancing information is handled, you might get
slightly above 32 bytes per node. In that case, a call to new might
actually reserve something like 48 or 64 bytes per node, which would be 6
to 8 times more than you calculated.
Do you think its truly out of memory or am I trampling on on memory I
shouldn't be. I don't think I am.

One other thing is that I have exception handlers in place but they are
not catching the exception so I'm not sure whats going on there.

Thanks for any help.
Regards


Aug 21 '05 #3
Kai-Uwe Bux wrote:

Also, keep in mind that the new/delete mechanism is likely to add another
word of memory to keep track of how much memory can be reclaimed at delete.
Thus, depending on how balancing information is handled, you might get
slightly above 32 bytes per node. In that case, a call to new might
actually reserve something like 48 or 64 bytes per node, which would be 6
to 8 times more than you calculated.


Yup, map and set use far more memory than one might expect, especially
for small data objects. A vector or a deque would make much better use
of available memory when you need to manage such a large number of objects.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Aug 21 '05 #4
Thanks for replying.

I'm never sure how many objects I'll need, it depends on the data. I
could have up to 300 million but it's doubtful. I understand that I
could never actually hold that many but I was hoping for a higher
number than 19 million.

I'm trying to catch std::exception bad_alloc and I don't have the file
handy so I'm not sure what is being thrown. I'll check it out next
crash.

Thanks

Aug 21 '05 #5
ok thanks. I was going to try vector but I calculated the bytes to be
higher than that of the map so I figured why bother, but I'll give it a
try.

Aug 22 '05 #6
I'm trying the vector class now but it's running really really slow, I
don't think it'll get to 19 million any time soon and this is in
release mode.

Since I was trying to emulate the map class what I did was create the
bitset object, do a find on the vector class and if it finds it, it
updates an internal counter otherwise it adds the object to the vector.

It must be the find call that's slowing it down drastically.

Any other thoughts?

Thanks again

Aug 22 '05 #7
Rich S wrote:
I'm trying the vector class now but it's running really really slow, I
don't think it'll get to 19 million any time soon and this is in
release mode.

Since I was trying to emulate the map class what I did was create the
bitset object, do a find on the vector class and if it finds it, it
updates an internal counter otherwise it adds the object to the vector.

It must be the find call that's slowing it down drastically.

Any other thoughts?


searching a map is O(lnN), searching a vector is O(N).

G
Aug 22 '05 #8
Rich S wrote:
I'm trying the vector class now but it's running really really slow, I
don't think it'll get to 19 million any time soon and this is in
release mode.

Since I was trying to emulate the map class what I did was create the
bitset object, do a find on the vector class and if it finds it, it
updates an internal counter otherwise it adds the object to the
vector.

It must be the find call that's slowing it down drastically.

Any other thoughts?


You could try a map that uses a more memory efficient algorithm. A hash
table would probably be better. I have a similar problem with a program that
likes to store as many small objects as it can in a std::set object.
Depending on the exact object size it can store maybe 15 million before it
runs out of memory. The std::set also uses nodes with three pointers, so I'm
going to try a hash-table instead.

Are you deleting objects from the map as well as adding them? If not you can
use a memory allocator that has zero overhead per allocated block and save a
few more bytes per allocation. Such an allocator can only free all the
memory it's allocated at once and not individually allocated blocks, but
that's all you need if you aren't deleting objects except when the map is
destroyed. I use that kind of allocator with my std::set of small objects.

DW
Aug 22 '05 #9
if you are running your application on windows and are not sure what
type of exceptions are being thrown then u can look up the structured
exception handling in windows (SEH)
to see if those exceptions are being thrown.

windows throws these exceptions in certain cases (eg. when no more
stack space could be allocated).
thanks
rt

Aug 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7212
by: Mee Yamo | last post by:
Fellas!! This is a very complicated one and it took me a few days to figure out exactly what's going on, but here's the final story: I have a production environment running on .NET with a SQL Server (2000, SP3). The SQL Server is on a dedicated Proliant computer with 2GB RAM (the actual SQLServer.exe process has dynamic memory assignment and can reach up to 1.6GB RAM). Nothing else is running on that specific computer.
8
2691
by: nickdu | last post by:
I'm trying to isolate "applications" into their own application domain within a single process. I've quoted applications because it's a logical representation of an application. Basically it consists of a bunch of components supplied by some application group. I got this to work, somewhat. The problem is that the application performs roughly (and this has not been measured, but a guess based on the rendering of the application GUI) 10x...
7
8181
by: Rob | last post by:
I am an Access developer and have done many Access databases in the standard Front-end on the workstations, backend on the server (over a LAN) but have never worked with Access over Citrix, though that situation is coming up for me shortly. Question: When you run the front-end on the Server, does Citrix clone the front end application database file for each user that connects or do they all connect to physically the same front-end...
8
1466
by: Kathy Burke | last post by:
Hi. Yet another question. We're running a new asp.net app off a production network server. The PC is a PentiumII/III with 128MB of RAM. When running the app, the memory uses read at about 190MB. Just looking for some opinions. The app is not that complicated. Runs on our internet. Some SQL db used and HTML docs are rendered using XmlTransform class.
0
1063
by: Mike P. | last post by:
I have a memory issue with .NET, as you all know by now .NET takes a lot of memory, however with the promise to give it back, if the system is running on low resources. I have a target machine with very specific hardware of 512M running XP with no virtual memory. When I ran my GUI application which is very rich in GDI we hit 150M of private bytes. Task manager shows the working size, however it is irrelevant, what matters is the private...
4
1371
by: klar02 | last post by:
We have a web server with 2GB of physical memory on it and we are seeing the memory usage running over 800,000KB in Task Manager. We have seen instances where the memory being this high(due to problems with ColdFusion) has caused the server to hang but this server is not hanging. Can anyone give me a little insight on when garbage collection should run and if it should be running before we get to 800,000KB(800MBG)? We are wondering if...
5
2309
by: writeson | last post by:
Hi all, I'm wondering if anyone has tried a scenario that I'm thinking of. At my job we've got a web based product provided by Apache running PHP that accesses MySQL. This web application is hosted by multiple servers behind a load balancer because of the user load on the system. However, we've still had times when the servers got over run and Apache maxes out on the number of httpd processes (257) and falls behind to the point of...
3
1401
by: Andy Klare | last post by:
We are seeing that the aspnet_wp is running out of memory shortly after deploying changes to a project. We use Visual Studio Copy Project and sometimes copy the files manually using copy and paste. This would be a ..NET 1.1 project. Has anyone experienced this and is there a solution or procedure that can reduce it? Any thoughts on this would be appreciated.
6
2204
by: dspfun | last post by:
I would like to analyze my running c-program. What I would like to know for example is the range of the entire address space of my running c-program (memory reserved for/by the running program), starting address and sizes of text (code), stack, heap, bss, constant data, linked in libraries, etc. What are some good ways to extract this kind of information? What (free) tools are the most common ones for displaying this kind of
4
2854
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding resources about the best practices to do that. I've found a lot of email discussions that say something like, "You need to educate yourself about the differences when you have long- running processes" but I've not had a lot of luck with finding things that explain the differences. I've seen some...
0
9721
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
10640
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
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
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...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
3
3015
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.