STL Alternative

前端 未结 15 1816
故里飘歌
故里飘歌 2021-01-31 04:24

I really hate using STL containers because they make the debug version of my code run really slowly. What do other people use instead of STL that has reasonable performance for

相关标签:
15条回答
  • 2021-01-31 04:33

    What about the ACE library? It's an open-source object-oriented framework for concurrent communication software, but it also has some container classes.

    0 讨论(0)
  • 2021-01-31 04:37

    Sorry, I can't leave a comment, so here's an answer: EASTL is now available at github: https://github.com/paulhodge/EASTL

    0 讨论(0)
  • 2021-01-31 04:38

    STL containers should not run "really slowly" in debug or anywhere else. Perhaps you're misusing them. You're not running against something like ElectricFence or Valgrind in debug are you? They slow anything down that does lots of allocations.

    All the containers can use custom allocators, which some people use to improve performance - but I've never needed to use them myself.

    0 讨论(0)
  • 2021-01-31 04:39

    For big, performance critical applications, building your own containers specifically tailored to your needs may be worth the time investment.

    I´m talking about real game development here.

    0 讨论(0)
  • 2021-01-31 04:39

    If you're using Visual C++, then you should have a look at this:

    http://channel9.msdn.com/shows/Going+Deep/STL-Iterator-Debugging-and-Secure-SCL/

    and the links from that page, which cover the various costs and options of all the debug-mode checking which the MS/Dinkware STL does.

    If you're going to ask such a platform dependent question, it would be a good idea to mention your platform, too...

    0 讨论(0)
  • 2021-01-31 04:41

    MSVC uses a very heavyweight implementation of checked iterators in debug builds, which others have already discussed, so I won't repeat it (but start there)

    One other thing that might be of interest to you is that your "debug build" and "release build" probably involves changing (at least) 4 settings which are only loosely related.

    1. Generating a .pdb file (cl /Zi and link /DEBUG), which allows symbolic debugging. You may want to add /OPT:ref to the linker options; the linker drops unreferenced functions when not making a .pdb file, but with /DEBUG mode it keeps them all (since the debug symbols reference them) unless you add this expicitly.
    2. Using a debug version of the C runtime library (probably MSVCR*D.dll, but it depends on what runtime you're using). This boils down to /MT or /MTd (or something else if not using the dll runtime)
    3. Turning off the compiler optimizations (/Od)
    4. setting the preprocessor #defines DEBUG or NDEBUG

    These can be switched independently. The first costs nothing in runtime performance, though it adds size. The second makes a number of functions more expensive, but has a huge impact on malloc and free; the debug runtime versions are careful to "poison" the memory they touch with values to make uninitialized data bugs clear. I believe with the MSVCP* STL implementations it also eliminates all the allocation pooling that is usually done, so that leaks show exactly the block you'd think and not some larger chunk of memory that it's been sub-allocating; that means it makes more calls to malloc on top of them being much slower. The third; well, that one does lots of things (this question has some good discussion of the subject). Unfortunately, it's needed if you want single-stepping to work smoothly. The fourth affects lots of libraries in various ways, but most notable it compiles in or eliminates assert() and friends.

    So you might consider making a build with some lesser combination of these selections. I make a lot of use of builds that use have symbols (/Zi and link /DEBUG) and asserts (/DDEBUG), but are still optimized (/O1 or /O2 or whatever flags you use) but with stack frame pointers kept for clear backtraces (/Oy-) and using the normal runtime library (/MT). This performs close to my release build and is semi-debuggable (backtraces are fine, single-stepping is a bit wacky at the source level; assembly level works fine of course). You can have however many configurations you want; just clone your release one and turn on whatever parts of the debugging seem useful.

    0 讨论(0)
提交回复
热议问题