Link to home
Start Free TrialLog in
Avatar of steveo225
steveo225Flag for United States of America

asked on

St9bad_alloc exceptions

I am getting random St9bad_alloc exceptions when trying to create a vector of floats that is sized at 16M (64MB) from many threads. I have gone through a number of tests and system parameters and cannot seem to figure out the cause. At first, the problem was happening quite often, until I noticed the stacksize limit was low low. I changed the stacksize and heapsize to unlimited and tried again. This time, the error occurs much less often. I monitored the system memory being used, and swap is not being used at all, and main memory still has 1.5GB free. Any ideas on what would cause this? Please let me know if you need more information. Thanks for the help!
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

>> when trying to create a vector of floats that is sized at 16M (64MB) from many threads.
Many threads one vector or many threads each with it's own vector? How many threads are we talking here? Can you show the code?
Avatar of steveo225

ASKER

The code is too complex to show. There are never more than 5 threads, vectors are not shared between threads (they are local to the thread function), and each thread has no more than 6 of these float vectors.

Thus, there should never be more than 30 float vectors, and if each float vector reached its max size of 64MB, that's a little less than 2GB. The box has 6GB physical memory, and top (on a 0.5 second refresh) never shows the available memory go below 1.5GB.
>> that's a little less than 2GB
Is this a 32 bit or 64 bit platform? A process can only address, at most, 2GB per process on a 32bit machine. Also, you have to take into consideration memory fragmentation. You have have free memory but you a big enough contiguous chunk to allocate for the processes needs.
64 bit machine, so addressing is not an issue. Fragmentation should not be an issue, because each buffer is 64MB but over 1.5GB is available. The app itself only ever uses 52% of the available 6GB memory. No other apps are running (aside from standard linux components).  This problem is hurting my brain.
>> 64 bit machine, so addressing is not an issue.
Ok, are you sure your kernel supports 64bit addressing? Have you tried writing a small program that tries to allocate > 2GB? If this works modify it to > 4GB. Does that also work?
Yes, in fact, the application in question uses 3.1GB at one point. I have run tests where the system was using all 6GB physical memory and ~1GB swap without issue.

You bring up an interesting point though, perhaps the app in question is not being compiled as a 64-bit app. I am not sure how to test that thought though. Is there a tool that can tell you if an application is 32 or 64 bit?
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's it. It is being compiled as 32-bit rather than 64-bit. Now I just have to figure out why. Thanks a ton!
Heh, No worries :)
>> Now I just have to figure out why
Make sure you have 64bit binutils installed.
http://sourceware.org/binutils/
I think it is a compiler issue, using the intel c compiler on AMD hardware, or just missing a flag