
size limit in list-sort-unique or am I messed up
I was surprised to see my list of strings get truncated when I had a large
number of items in the list.
With 20,000 items in the list I could sort and make sure they were unique.
But when the number of items in the list went up to 40,000 the number of
items was truncated.
Am I hitting a maximum size of one of the data types? If so is there an easy
work around?
Thanks,
LM
#include "stdafx.h"
#pragma warning(disable:4786) // for STL implementation
#include <list>
#include <string>
using namespace std;
typedef list<string, allocator<string> > LIST_STR;
// comment out this next line to see the problem
//#define WORKS_OK
#ifdef WORKS_OK
#define SIZE 10000
#else
#define SIZE 20000
#endif
int main(int argc, char* argv[])
{
LIST_STR list;
LIST_STR::iterator it;
int i;
char c[256];
// fill the list
for (i=0; i < SIZE; i++)
{
list.push_back(itoa(i, c, 10));
}
printf("list size = %d\n", list.size());
// add some duplicates to the list
for (i=0; i < SIZE; i++)
{
list.push_back(itoa(i, c, 10));
}
printf("list size after adding duplicates= %d\n", list.size());
list.sort();
printf("list size after sort= %d\n", list.size());
list.unique();
printf("list size after unique= %d\n", list.size());
return 0;
Quote:
}
//output
//list size = 20000
//list size after adding duplicates= 40000
//list size after sort= 7232
file://list size after unique= 7232