Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do multiple threads eat my memory

I have a Windows C++ application that holds a std::hash_set containing abount 5 Million entries each with 32 Bytes. If i create the hash_set in a separate (of many) threads it uses > 1 GB according to ProcessExplorer. I see this when i free the list. If i create it in the main thread it ueses 200 MB. This phenomenon only applies to the 32-Bit Version of my application. It does not oocur with the x64 Version. I use a dual quad core with Win XP x64. Its not a memory leak. Everything is freed on clear().

My guess: Windows 32.Bit is not constructed for many threads / many cores.

What is your gues?

like image 633
RED SOFT ADAIR Avatar asked May 22 '26 23:05

RED SOFT ADAIR


1 Answers

The data structure ultimately allocates from the heap, and it's the same heap regardless of the thread. Making heap calls from a different thread is not going to affect the amount of memory allocated. Either your tools are lying to you, or you're allocating the hash_set on several other threads by accident.

like image 130
Daniel Earwicker Avatar answered May 25 '26 13:05

Daniel Earwicker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!