Josh Posted June 7, 2012 Share Posted June 7, 2012 If I declare a list, map, or stringstream in a function, and call that function, my memory usage goes up when the function ends and the stl object goes out of scope. Does STL use a funny memory pool or something? This is all it takes: void MyFunc() { std::list<int> list; } mem1=System::GetMemoryUsage(); MyFunc(); mem2=System::GetMemoryUsage(); And my memory usage increases by 12 bytes. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted June 7, 2012 Share Posted June 7, 2012 STL containers work kinda like BASIC: they make sure the zero element exists, is initialized. That's why they take up initial memory, but it's totally meaningless because you actually want to populate the container, and if not, then don't declare it. Where STL really comes to play is in the speed. Even an ineffective iteration through a vector is faster than an native Fortran linked list. I don't know how they do it, but it's insane fast. Windows cleans up all leaked memory, but it doesn't do it immediately. That's why it's kinda "OK" to not call delete, but just let windows clean the memory up. I mean in the sense that your game reserves the memory what it needs, so there is no harm done to the game itself. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Furbolg Posted June 7, 2012 Share Posted June 7, 2012 Josh as you declared your std::list on the stack it should.. no must.. be cleaned up after leaving the scope. Are you sure your System::GetMemoryUsage() works correctly ? To verify it, please check your Ressourcemonitor on the RAM Tab. **edit** Quote Link to comment Share on other sites More sharing options...
Josh Posted June 7, 2012 Author Share Posted June 7, 2012 Gah, I was measuring total allocations. This is the correct code: long System::GetMemoryUsage() { #ifdef _WIN32 #ifdef _DEBUG //Exact memory usage, but only works in debug mode: _CrtMemState memstate; _CrtMemCheckpoint(&memstate); return memstate.lSizes[0]+memstate.lSizes[1]+memstate.lSizes[2]+memstate.lSizes[3]+memstate.lSizes[4]; #else //Only gives approximate results, but works in release mode: long sz=0; HANDLE proc = GetCurrentProcess(); PPROCESS_MEMORY_COUNTERS ppsmemCounters=new PROCESS_MEMORY_COUNTERS; if (GetProcessMemoryInfo(proc,ppsmemCounters,sizeof(PROCESS_MEMORY_COUNTERS))) { sz=ppsmemCounters->WorkingSetSize } delete ppsmemCounters; return sz; #endif #endif } Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Benton Posted June 8, 2012 Share Posted June 8, 2012 I love how the developer asks the community questions, and gets help, It really is a good way for us to give back to the hard working developer, and strengthens the community. This is the first time I have ever seen this, this community is the tightest one I have ever seen. Quote Windows 7 Professional 64 bit, 16 gigs ram, 3.30GHz Quad Core, GeForce GTX 460 one gig, Leadwerks 2.5, Blender 2.62, Photoshop CS3, UU3D Link to comment Share on other sites More sharing options...
Furbolg Posted June 8, 2012 Share Posted June 8, 2012 Maybe Josh should pay us or give us rabatte on LE3D **disclaimer: this statement was meant to be funny / joke ** Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.