List losing elements on sort

Hi all,

I'm trying to write code (in Visual Studio 6) to generate a number of test customer entries which will allow me to get some timings from another program. The main aim is to generate upto 1 million numbers in numerical order.

All seems okay until I use a sort, after which the size of the list drops.

The code snippet that generates the numbers:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
	srand(time(NULL));
	logMessage("Generating " + ltos(iGenCount) + " customer numbers");
	list<long> customers;
	list<long>::iterator it;
	cout << "List max size:" << customers.max_size() << endl;

	for(i = 0; i < iGenCount; i++) {
		customers.push_back(getNewCustomer());
	}
	cout << "Size: " << customers.size() << endl;
	customers.sort();
	cout << "Size: " << customers.size() << endl;
	customers.unique();
	cout << "Size: " << customers.size() << endl;

	logMessage("Generated " + ltos(customers.size()) + " customers");

the getNewCustomer() function returns a long (min 4 digits, max 9 digits).

The output is:
1
2
3
4
5
6
10:52:27: Generating 50000 customer numbers
List max size:1073741823
Size: 50000
Size: 17232
Size: 16287
10:52:27: Generated 16287 customers


If I code an iterator loop to output the contents then it stops at the lower number (16,287).

The limit on generation is around 32,000 which makes me think it's an int problem?

I've tried searching Google but to no avail.

Any help greatly appreciated.
Last edited on
unique() removes duplicates. You must have customers with the same numbers.
I understand that unique will remove duplicate entries but it's the sort that I'm having trouble with.

In the ouput above:
50,000 - Size of list after populating
17,232 - Size of list after sort
16,278 - Size of list after sort then unique

So after a sort I've lost 32,768 elements!
I've substituted rand() for getNewCustomer() and run your code. It doesn't loose anything.

May I suggest that your problem is in code you haven't posted.
A lucky Google strike!

I wondered if the 37,768 was relevant and added it to a google search and voila! One page described the same problem I'm having and points here: http://support.microsoft.com/kb/240014/en-us

Looks as though it's a MS VC thing.

Edited the list header file, recompiled and all okay.

Many thanks for looking at the code kbw, hope you didn't spend too much time on it.


Last edited on
Topic archived. No new replies allowed.