Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. STL list sort() limit

STL list sort() limit

Scheduled Pinned Locked Moved ATL / WTL / STL
c++cssquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GMoss
    wrote on last edited by
    #1

    Hi, Can anyone tell me if there is a limit of 2^15 (32768) items that can be sorted in a list using the list function sort()? I am trying the following code in Visual C++ 6 on Windows 2000. std::list TestList; for (int i=0; i<40000; i++) TestList.push_back(i); int nSize = TestList.size(); test.sort(); int nSize2 = TestList.size(); nSize is 40000. nSize2 is 7232. The difference between the two values is always 32768. Less than 32768 values sorts fine. NOTE: max_size() returns a value of > 100000000. I could not find any information that mentions this limit but it is clearly there. Can anyone suggest an alternative?

    J Z 2 Replies Last reply
    0
    • G GMoss

      Hi, Can anyone tell me if there is a limit of 2^15 (32768) items that can be sorted in a list using the list function sort()? I am trying the following code in Visual C++ 6 on Windows 2000. std::list TestList; for (int i=0; i<40000; i++) TestList.push_back(i); int nSize = TestList.size(); test.sort(); int nSize2 = TestList.size(); nSize is 40000. nSize2 is 7232. The difference between the two values is always 32768. Less than 32768 values sorts fine. NOTE: max_size() returns a value of > 100000000. I could not find any information that mentions this limit but it is clearly there. Can anyone suggest an alternative?

      J Offline
      J Offline
      jbarton
      wrote on last edited by
      #2

      It looks like there is a bug in the list sort routine which ships with VC 6.0. Looking at the source in , it appears that the internal array used to process the merge sorts is not being handled properly when the array is full. You might be able to find a fix for this by getting an upgrade to the STL that you use. This isn't a bad idea, as there are a number of problems with the STL that ships with VC 6.0. For a quick fix, you could patch the header file so that the sort works correctly. Or you could write your own sort routine which fixes the problem. (just glancing at it, it appears that the sort could be fixed by changing the following sequence: if (_I == _MAXN) _A[_I].merge(_X); else {_A[_I].swap(_X); if (_I == _N) ++N; }} to the following: if (_I == _MAXN) _A[_I].merge(_X); else _A[_I].swap(_X); if (_I == _N) ++N; } Note: I only briefly tested this, but it appears to work. The other choice (if you are going change ) is to increase the const _MAXN to a larger number, so that the temporary array can fit more elements. Each increase of this number doubles the size of the list that can be sorted. By setting this to 32, it should be able to handle any size list that you could create. Best regards, John

      1 Reply Last reply
      0
      • G GMoss

        Hi, Can anyone tell me if there is a limit of 2^15 (32768) items that can be sorted in a list using the list function sort()? I am trying the following code in Visual C++ 6 on Windows 2000. std::list TestList; for (int i=0; i<40000; i++) TestList.push_back(i); int nSize = TestList.size(); test.sort(); int nSize2 = TestList.size(); nSize is 40000. nSize2 is 7232. The difference between the two values is always 32768. Less than 32768 values sorts fine. NOTE: max_size() returns a value of > 100000000. I could not find any information that mentions this limit but it is clearly there. Can anyone suggest an alternative?

        Z Offline
        Z Offline
        ZoogieZork
        wrote on last edited by
        #3

        This is a known bug. See the following page for how to patch your VC6 STL headers for a number of known bugs: http://www.dinkumware.com/vc_fixes.html[^] In particular, see the "Fix to <list>" section. - Mike

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups