Click here to Skip to main content
15,888,802 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: find the largest 1000 values Pin
David Crow10-Nov-07 4:03
David Crow10-Nov-07 4:03 
AnswerRe: find the largest 1000 values Pin
George_George10-Nov-07 4:13
George_George10-Nov-07 4:13 
QuestionRe: find the largest 1000 values Pin
David Crow16-Nov-07 9:36
David Crow16-Nov-07 9:36 
AnswerRe: find the largest 1000 values Pin
BadKarma7-Nov-07 21:28
BadKarma7-Nov-07 21:28 
GeneralRe: find the largest 1000 values Pin
George_George7-Nov-07 21:54
George_George7-Nov-07 21:54 
GeneralRe: find the largest 1000 values Pin
BadKarma7-Nov-07 22:42
BadKarma7-Nov-07 22:42 
GeneralRe: find the largest 1000 values Pin
George_George8-Nov-07 3:52
George_George8-Nov-07 3:52 
QuestionRe: find the largest 1000 values Pin
shpid3r8-Nov-07 6:10
shpid3r8-Nov-07 6:10 
Hello!

I`m not that of an expert to provide scientific solutions, but having your problem and trying not to take into account what others have said before (nth_element and Map don`t tell anything to me, yet), I`m thinking at two solutions:

You say that you have the data into files. Well then, why not reading them line by line (or using a buffer, I don`t know the format of your file(s)) and by this way you will only work on several MBs of RAM, the rest is either read or will be read, but stored into that file.
--
For example, use a buffer of 5000 elements. Read the first 5000 elements. While reading them, you could already start building the Highest1000 vector (which I also suggest you sort it after adding one value, for efficiency). Read the next 5000 elements... modify the Highest1000 vector... and so on.
---
It might take some time, i know, but you don`t kill your computer and ... if you need the application to do something else while sorting, try using a multithreaded application.
--Even more effective it would be a thread to do reading/writing aspects, and another one to do the sorting and interplacing the new values (I`m afraid I cannot provide so much information on how to make the 2 treads work synchronous - global variables is all that comes to me)

The 2nd solution is actually adding to the first one, by saving your partial results into another file. So: if now let`s say you have 1G of data, save the highest 1000 highest values, and the next time you run your app and this time you have 2Gs of data, address the rest (which is 1G, again).

If timing is such a concern, you should think that actually this is the way Windows overcomes the lack of RAM, by writing data to HDD. It`s true that the system might get slow while reading/writing into files, but that`s the nature of your application. When working with such amounts of data, you cannot expect a pocket pc to do it while serving other applications and doing it fast. You say that you have 2G of memory, which is enough ...

Please provide feedback, I`ve been thinking to your problem and I`m interested in your result.
Cool | :cool:
Best Wishes,
Shpid3r


PS: sorting is done the fastest by splitting in 2: let`s say the first position of Highest1000 vector is the lowest value, and that the last value (while adding, so not the 1000th) is the highest. Then, compare with the last one, then with the one at the half, and so on...

AnswerRe: find the largest 1000 values Pin
George_George8-Nov-07 21:08
George_George8-Nov-07 21:08 
GeneralRe: find the largest 1000 values Pin
David Crow9-Nov-07 2:47
David Crow9-Nov-07 2:47 
GeneralRe: find the largest 1000 values Pin
George_George9-Nov-07 3:14
George_George9-Nov-07 3:14 
Answerhere is my algorithm. [modified] Pin
chandu00410-Nov-07 1:02
chandu00410-Nov-07 1:02 
GeneralRe: here is my algorithm. Pin
David Crow10-Nov-07 4:05
David Crow10-Nov-07 4:05 
GeneralRe: here is my algorithm. Pin
George_George10-Nov-07 4:15
George_George10-Nov-07 4:15 
QuestionCString to TCHAR & TCHAR to CString Pin
Paulraj G6-Nov-07 20:29
Paulraj G6-Nov-07 20:29 
AnswerRe: CString to TCHAR & TCHAR to CString Pin
Cedric Moonen6-Nov-07 20:43
Cedric Moonen6-Nov-07 20:43 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Paulraj G6-Nov-07 20:59
Paulraj G6-Nov-07 20:59 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Cedric Moonen6-Nov-07 21:05
Cedric Moonen6-Nov-07 21:05 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
CPallini6-Nov-07 21:14
mveCPallini6-Nov-07 21:14 
AnswerRe: CString to TCHAR; TCHAR to CString [incorrect] [modified] Pin
Llasus6-Nov-07 21:06
Llasus6-Nov-07 21:06 
GeneralHonestly Pin
CPallini6-Nov-07 21:28
mveCPallini6-Nov-07 21:28 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Cedric Moonen6-Nov-07 21:34
Cedric Moonen6-Nov-07 21:34 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
Raj Prathap7-Nov-07 0:09
Raj Prathap7-Nov-07 0:09 
GeneralRe: CString to TCHAR & TCHAR to CString Pin
toxcct7-Nov-07 0:30
toxcct7-Nov-07 0:30 
AnswerRe: CString to TCHAR & TCHAR to CString Pin
toxcct7-Nov-07 0:28
toxcct7-Nov-07 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.