Click here to Skip to main content
15,914,391 members
Home / Discussions / C#
   

C#

 
GeneralRe: Insert Obejct to sorted list Pin
bonzaiholding26-Jul-09 6:15
bonzaiholding26-Jul-09 6:15 
GeneralRe: Insert Obejct to sorted list Pin
PIEBALDconsult26-Jul-09 6:26
mvePIEBALDconsult26-Jul-09 6:26 
GeneralRe: Insert Obejct to sorted list [modified] Pin
bonzaiholding26-Jul-09 6:31
bonzaiholding26-Jul-09 6:31 
GeneralRe: Insert Obejct to sorted list Pin
PIEBALDconsult26-Jul-09 6:51
mvePIEBALDconsult26-Jul-09 6:51 
GeneralRe: Insert Obejct to sorted list Pin
bonzaiholding26-Jul-09 20:39
bonzaiholding26-Jul-09 20:39 
GeneralRe: Insert Obejct to sorted list Pin
Luc Pattyn26-Jul-09 11:32
sitebuilderLuc Pattyn26-Jul-09 11:32 
GeneralRe: Insert Obejct to sorted list Pin
PIEBALDconsult26-Jul-09 14:49
mvePIEBALDconsult26-Jul-09 14:49 
AnswerRe: Insert Obejct to sorted list Pin
Martijn Boeker26-Jul-09 21:55
Martijn Boeker26-Jul-09 21:55 
I think you can do it this way.

In the loop, first collect the values (without sorting) in a list up to a certain number, say 1000 values. When it reaches 1000 values, re-sort the list and keep only the top 100 using GetRange(). Then continue adding to the list. This will prevent the algorithm from sorting all the time while keeping memory usage limited. The number 1000 should be a variable and you should experiment with it to find a value that gives you the best performance.

In your example:

int maxSize = 1000;

for (int num1 = 1; num1 <= 100; num1++)
for (int num2 = 1; num2 <= 100; num2++)
{
  //Create the current Example
  Example e1 = new Example();
  e1.num1 = num1;
  e1.num2 = num2;

  //Insert into list 
  m_List.Add(e1);

  // Sort only after certain treshold.
  if (m_List.Count >= maxSize)
  {
    // sort
    m_List.Sort();

    // Get top 100.
    m_List = m_List.GetRange(0, 100);
  }
}

// Sort and select top 100 after loop, because the list may be between 100 and maxSize.

// sort
m_List.Sort();

if (m_List.Count > 100)
{
  // Get top 100.
  m_List = m_List.GetRange(0, 100);
}


I must agree though, doing this 10^50 times is impossible. Your computer does something in the order of 10^9 processor instructions per second, per day say 10^14, per year say 10^16, in a hundred years 10^18... (I may be a bit off, but you get the idea..) Or are there any mice involved? Big Grin | :-D
GeneralRe: Insert Obejct to sorted list Pin
bonzaiholding26-Jul-09 22:40
bonzaiholding26-Jul-09 22:40 
GeneralRe: Insert Obejct to sorted list Pin
Martijn Boeker27-Jul-09 9:19
Martijn Boeker27-Jul-09 9:19 
Generalreality check Pin
Luc Pattyn27-Jul-09 10:47
sitebuilderLuc Pattyn27-Jul-09 10:47 
QuestionHow do I add the floating Toolbar with TabPage like "Might and Magic V Map Editor" Pin
akira3225-Jul-09 22:46
akira3225-Jul-09 22:46 
AnswerRe: How do I add the floating Toolbar with TabPage like "Might and Magic V Map Editor" Pin
Abhijit Jana26-Jul-09 3:12
professionalAbhijit Jana26-Jul-09 3:12 
GeneralRe: How do I add the floating Toolbar with TabPage like "Might and Magic V Map Editor" Pin
akira3227-Jul-09 6:45
akira3227-Jul-09 6:45 
QuestionInsert object to a sort list in the most efficient way Pin
bonzaiholding25-Jul-09 22:39
bonzaiholding25-Jul-09 22:39 
AnswerRe: Insert object to a sort list in the most efficient way Pin
PIEBALDconsult26-Jul-09 4:53
mvePIEBALDconsult26-Jul-09 4:53 
QuestionWhen Firefox in work Pin
Fullmm25-Jul-09 21:37
Fullmm25-Jul-09 21:37 
AnswerRe: When Firefox in work Pin
Abhijit Jana25-Jul-09 21:46
professionalAbhijit Jana25-Jul-09 21:46 
AnswerRe: When Firefox in work Pin
Manas Bhardwaj25-Jul-09 22:18
professionalManas Bhardwaj25-Jul-09 22:18 
Questionmonitoring for iexplore.exe Pin
msgreat25-Jul-09 19:23
msgreat25-Jul-09 19:23 
AnswerRe: monitoring for iexplore.exe Pin
PIEBALDconsult25-Jul-09 19:30
mvePIEBALDconsult25-Jul-09 19:30 
GeneralRe: monitoring for iexplore.exe Pin
msgreat25-Jul-09 19:34
msgreat25-Jul-09 19:34 
GeneralRe: monitoring for iexplore.exe Pin
PIEBALDconsult25-Jul-09 19:43
mvePIEBALDconsult25-Jul-09 19:43 
GeneralRe: monitoring for iexplore.exe Pin
msgreat25-Jul-09 19:50
msgreat25-Jul-09 19:50 
GeneralRe: monitoring for iexplore.exe Pin
Giorgi Dalakishvili25-Jul-09 22:49
mentorGiorgi Dalakishvili25-Jul-09 22:49 

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.