|
bonzaiholding wrote: more then 10^50 Items
Stop right there, no need to optimize anything, there isn't enough life in your PC to ever finish such a job, provided you would be willing to pay for the energy it will take.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
But they're very small items. Waffer thin.
|
|
|
|
|
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++)
{
Example e1 = new Example();
e1.num1 = num1;
e1.num2 = num2;
m_List.Add(e1);
if (m_List.Count >= maxSize)
{
m_List.Sort();
m_List = m_List.GetRange(0, 100);
}
}
m_List.Sort();
if (m_List.Count > 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?
|
|
|
|
|
This is what i did, The problem is that every iteration i need to sort the list that is allready sorted.
The Only thing that i need is to Insert the object into the right place in the sorted list and then Remove the last object on the list.
Do you have any idea what can i do?
modified on Monday, July 27, 2009 7:27 AM
|
|
|
|
|
With the solution I propose, this is not the case. You would only sort every so often, not with every iteration. Now I think about it, this may still be slow, because you would have to sort a larger list.
I suppose you could also use a LinkedList (for fast insert/remove) and implement some kind of binary search to find the index to insert at. LinkedList doesn't seem to have a BinarySearch() method, but I'm sure you can find an example of binary search somewhere. I think that would give you the best performance.
|
|
|
|
|
You still don't get it, do you?
assuming a fantastic CPU that does everything your algorithm needs for one iteration in a single instruction (waw), and runs at 1000GHz (waw), so it does 1 of your zillion things per picosecond, or 3E19 per year (as there are 3E7 seconds in a year); now assume it started when the universe started (some 14E9 years ago?), then it would now have finished some 4E29 thereof, way less than 1E50 (you're twenty zeroes short).
so sorting isn't relevant, your algorithm stinks, it is just undoable that many times.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
The Might and Magic V Map Editor's floating Toolbar with TabPage as below:
http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/Visual%20C%7C3/MapEditor%7C_Might%20and%20Magic%20V%20Map%20Editor.JPG
How do I design the same toolbar in Visual C# 2008?
|
|
|
|
|
Here is an Nice Example of Floating Toolbar. You have to design the internal content of Toolbar.
Floating Toolbar
modified on Sunday, July 26, 2009 12:44 PM
|
|
|
|
|
|
I have a list of specific class.
Im doing some simulation and i want to receive in the end the 100 best result.
Lets say i have this class :
class A<br />
{<br />
int j;<br />
int t;<br />
<br />
}
and i want to save in some range of j and t the best 100 "A" elements that give me the low math.pow(j/t,2) (100 result of the lowest A that i have).
Right now im insert the result to the list and then sort the list with the Compare method. each time a take the smallest result of the list and then if the current result is more small then then the small one on this. If its is smallest then i insert it into the the array , sort it and then remove the last object and continue.
What is the best way to take a List/Array of sort element and just insert the Current element to it's place in the sorted List/Array and remove that biggest element of the list ? (In C# )
modified on Sunday, July 26, 2009 7:46 AM
|
|
|
|
|
Do you really need to do that after each insert? Or can you fill the structure, then sort it and iterate the ones you want?
|
|
|
|
|
In the name of God
-----------------
Hi
Anybody know how we can find out Firefox in work ( loading page or downloading file , downloading image) ? please help me in any programing language .
best regards
bye.
|
|
|
|
|
Fullmm wrote: Anybody know how we can find out Firefox in work ( loading page or downloading file , downloading image) ?
Can you please explain it in little bit details? I am little bit confused .
You want to track information when Firfox downloading any file or Images ?
|
|
|
|
|
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I want to create a c# app. It should just display a message box, whenever I am opening Iexplorer.exe. How to do this friends? It should be run at background
|
|
|
|
|
Any way you like. I'd probably have it as a Windows Scheduled Task that starts at login.
|
|
|
|
|
ok., but How to do this in c#,
Which event will fired when browser invoked? Can I get example program?
I am new to c#.
|
|
|
|
|
I don't know what anyone else would do, but I'd likely start with calling FindWindow in an endless loop and doing whatever it is I want to do when I find one.
[
System.Runtime.InteropServices.DllImportAttribute
(
"User32"
,
SetLastError=true
,
EntryPoint="FindWindow"
)
]
private static extern System.IntPtr
API_FindWindow
(
string lpClassName
,
string lpWindowName
) ;
public static System.IntPtr
FindWindow
(
string WindowName
)
{
return ( API_FindWindow
(
null
,
WindowName
) ) ;
}
If no one gives you a better idea, then read up on P/Invoke to figure how to use this.
|
|
|
|
|
|
|
Hello everyone. I've successfully managed to control the general wave volume of Windows.
However, since vista came out, it's now possible to control the volume for every single application in the windows mixer..
Since I didn't manage to find anything anywhere here comes my question: how i can control per-application volume?
What I wanted to do was to mute/lower the volume of all BUT ONE application. ( also via some sendmessage codes I'm not aware of.. )
Can anyone help?
|
|
|
|
|
Is there a free IDE for designing a Winforms gui for a C# program? I have a copy of VS 2008 that I got from school, would that work?
Also, is Visual C# the same as C#? VS 2008 only doesn't list "C#", only "Visual C#".
Thank you.
|
|
|
|
|
You can use VS 08.. yap my friend this are same.
Thanks
Md. Marufuzzaman
|
|
|
|
|
C# is a language. Visual C# is Microsoft's compiler for C#. Visual Studio can be used as an IDE for Visual C#, and is quite handy (but not required) when you need to implement a WinForms application. An Express version of Visual Studio is available for free. And a C#-only version of Visual Studio is (or was) also available, marketed as Visual C# Standard (if I recall correctly).
|
|
|
|
|
How can I use Vscroll for listview when Scrollable is false ?
|
|
|
|