|
Som Shekhar wrote: Coding is easy.
I'm looking at a buglist right now which tells me that it's not as easy as English.
Som Shekhar wrote: As I mentioned, The trouble comes when multiple of such calculations happen together. I am currently working on multi-threading of different instances. Atleast to save some more time.
Have you seen the article[^] on the AForge.Parallel.For -class? It might help in building a prototype to measure against
Som Shekhar wrote: In this problem, calculation of fluid height is needed. There are multiple fluid columns and many such tubes. With drag and drop functionality
True, but it would also make an impressive interface
Som Shekhar wrote: Usually working with already implemented concepts is always better. Consider using a dictionary vs. implemented List with key.
I'd try to mirror the concept of a database in-memory; creating a list of the records, and the equivalent of an index. IQueryable[^] springs into mind.
Som Shekhar wrote: You would be surprised that i have come across such situation more than 4-5 times already while designing my applications. I usually work on disconnected database system and speed is a primary concern in loading and saving data.
I initially worked with datatables which worked fine when my application was young. As it grew older, datatables are damn slow. I moved to dictionary. So far, they are fine. Even today, i experience a max lag of 0.5-0.6 sec on a drag drop operation which isn't too much to worry about.
This post[^] confirms that although databases manipulate data very fast, your results are faster.
Som Shekhar wrote: By multi-threading, i hope to reduce it to around 0.1-0.2 which should be manageable. But it is good to keep up with concepts.
Usually a parallel solutions does wonders and thats what I was hoping here.
One could consider multiple ways to optimize, and I'm sure that would be some creative ways that'd get posted to do so. Using the Parallel.For class to lookup all the elements could be a good start.
Another, perhaps better implementation yet, would then be a readonly list, to describe a table like presented below. Instead of writing a null, your could launch a short lived thread to calculate it's distance to a yougest version in the list, that disctince gives you the index of the value that it actually stands for. This should be done when you load the data; you'd have to process it a bit of a time decoding it, but that also shortens the amount needed to retrieve data from that list. This would be an optimization on the readprocess, as you can forget about fetching it at all if it's really there. Moving this particular task to the method that's doing the initalization, lookups would be faster. The initialization-routine could also be (ab)used to dynamically enrich your data, if that would be required.
You could then do parallel lookups, each lookup falling back on it's PK - A Perhaps a HashTable<key, record="" [as="" struct!]="">. You'd would then already be pointing at all the correct values, for all correct columns, without having to worry for corruption. That's as long as the read is readonly and easily accessible by threads.
I'm of to bed, this kept going through my head all the time. I wonder if I'm now gonna dream about it?
I are Troll
|
|
|
|
|
Parallel.For looks promising. Will dig into it.
Currently, since i have already implemented multithreading, I guess no need to implement that for now.
Eddy Vluggen wrote: True, but it would also make an impressive interface
Oh you bet. These days, looks may not be everything but that is what sells the first.
I guess, that is it for now... I gotta be happy with multithreading for now. Since no other implementation already exist in this area.
It was great having some meaningful conversations.
|
|
|
|
|
Som Shekhar wrote: Oh you bet. These days, looks may not be everything but that is what sells the first.
Sad, but true.
Som Shekhar wrote: I guess, that is it for now... I gotta be happy with multithreading for now.
You're dividing your workload over multiple CPU's, there's not much room for improvement there. If you get unhappy in the future, try Brahma[^], that would give you the option to offload some work from the CPU to the GPU, abusing the graphics-card.
Som Shekhar wrote: It was great having some meaningful conversations.
Yup, engaging a conversation is simply more fun than posting an answer. Good luck with your venture
I are Troll
|
|
|
|
|
Brahma looks interesting!!!
Now, that we are talking of multi threading, why is it that we need to code for multi-threading?
If you look at any operating system that can support multiple processors, it automatically distributes work onto different cores. Can't there be a framework which can do the same without the need to code differently?
If a user defines a program priority as "High" or "RealTime" it only increases the share of thread time to current process. But no change in threading...
Am I missing something?
|
|
|
|
|
Som Shekhar wrote: Am I missing something?
The perversion to launch a new thread from a Visual Basic 6 application, I hope
Som Shekhar wrote: If a user defines a program priority as "High" or "RealTime" it only increases the share of thread time to current process. But no change in threading...
..and "realtime" isn't really realtime, but just the name of the highest level of priority.
Som Shekhar wrote: If you look at any operating system that can support multiple processors, it automatically distributes work onto different cores.
Though it feels that way, it's an illusion. A program is made up of a logical set of commands/instructions that get executed one after another. That's reflected in our applications; we expect that the second instruction won't be execute before the first instruction. A short example;
10 A$ = "Hello"
20 B$ = "World"
30 PRINT A$ + " " + B$ These three lines of code should be considered atomic, meaning that you don't want to distribute them over 2 different people to interpret. This is a task that can't be divided. One processor had access to it's own cache, and it's memory. Windows was created and started to fake multitasking. Applications would run (to line 20 in our example), get thrown into the deep-freeze, another application would be defrozen and run, ad infinitum. Do that very fast, and it seems to become a fluid movement.
Threads we're already there; it was preferred to launch your own thread instead of spawning a new process if you needed to do some additional tasks. Using a thread would cost less resources and they behaved like an additional proces, owned by some other (main)-thread. Fibers were introduced also, but those never gained popularity.
You wanted this processing to happen in "some other place" than the thread that ran your interface. Every Windows-application has a method that's called "WndProc", which Windows calls now and then to inform your application of mouse-movements that have occurred, or that certain parts of the form need to be repainted. Let's extend our example application;
10 REM Example :)
20 REM
30 WndProc:
40 MSG = GWBASIC_INTEROP.GETMESSAGE()
50 IF (MSG = WM_UIT) THEN
60 GOTO THE_END
70 END IF
80 IF (MSG = WM_PAINT) THEN
90 GOSUB SAY_HI
100 END IF
110 GOTO WndProc
120 SAY_HI:
130 FOR X = 1 TO 100
140 PRINT "Hello World, number " + X
150 NEXT X
160 RETURN
170 THE_END:
180 There's a loop that processes the messages, and there's code. This meant that if the processor was doing line 140, it would get frozen there in the middle of the job. This, as a consequence, means that the application wouldn't accept a "quit" message until it's finished doing those 100 iterations!
A thread is gets frozen with it's state, that's the reason why it's "illegal" to write into memory that another thread is working with, and the reason why the mainthread of any application is reserved to handle the UI.
The Parallel.For is an abstraction that creates multiple threads (let's take 4 as an example) to run a loop. One of the pre-requirements is that they shouldn't share variables that could mess up the way they work (because one has X=3, on X=4, and two have X=5). They should also say hello to the mainthread, before changing any of it's values. This model scaled to multiple processors.
SQL Express is limited to using a single processor, whereas SQL Server goes as far as making the processor-affinity a mere setting. Some applications still do their processing in the UI, easily recognizable by the white space that they show where a form should be. It's not a perfect situation, but it's often hard 'enough' to make an application run correctly with a single path-of-execution.
There is indeed a growing need for extra tools. The .NET Framework has a BackgroundWorker which makes it easy to manage a new line-of-execution, and you'll often find an Asynch-version for a method-call.
Som Shekhar wrote: Brahma looks interesting!!!
Sure does - there's a lot of GPU's onboard of the motherboards in the office without being used very much
I are Troll
|
|
|
|
|
Topic is long over, I am just loving the conversations
Eddy Vluggen wrote: and "realtime" isn't really realtime, but just the name of the highest level of priority
Yes, I know that... I guess you would know that Microsoft has told that one shouldn't use "RealTime" in their applications as it will freeze the OS. I wonder if they created a check to freeze the system if someone used "realtime" instead of letting the processor do the job.
Well, you are right about the process and threading. I agree fully when it comes to the concept of threading vs processes.
My question was a little different. I know that two processes are resource heave and thread do just the jobs quite well.
Let me try to suggest my concept here.
Lets say we got two classes "Car" and "Bike". Car has its own methods and so does the bike. We create two objects "Car1" and "Bike1" If these two are there in an application, all internal methods could be handled through a new thread and thus they will always be thread safe. Even two objects "Car1" and "Car2" will always be thread safe.
Instead of programmer creating such new threads and their completion events for each of the methods, the framework could automatically run them on new threads.
Is it that I have a plan for a new programming language? Am I talking weird?
|
|
|
|
|
Som Shekhar wrote: Topic is long over, I am just loving the conversations
Ditto, but we'd better move to the soapbox, or email
Som Shekhar wrote: Let me try to suggest my concept here.
Lets say we got two classes "Car" and "Bike". Car has its own methods and so does the bike. We create two objects "Car1" and "Bike1" If these two are there in an application, all internal methods could be handled through a new thread and thus they will always be thread safe. Even two objects "Car1" and "Car2" will always be thread safe.
Instead of programmer creating such new threads and their completion events for each of the methods, the framework could automatically run them on new threads.
Is it that I have a plan for a new programming language? Am I talking weird?
Not at all, sounds like a convenient way to distribute the load. One way to do so would be by instantiating a BackgroundWorker and passing the Bike to the RunWorkerAsync[^]-method. You'd only need locks where the objects need to share data.
Those objects still need to be 'invoked' from somewhere, and that somewhere is most likely going to be the mainthread. It doesn't make much sense to create an Async-version for every method or class, since threads still cost performance. Creating a thread to change Form.Visible is going to be rather inefficient.
If the Bike is a webserver-kind of class, then yes, it's the correct pattern. If the Bike is a DataGridViewColumn , then it might be wiser to keep the code rather short and simple anyway. If you need a long-running process happening in such a place, then move it to a backgroundworker and have them signalling status.
There's two other interesting places to visit;- Rx extensions[^], since collections are another example where easy multhithreading makes sense
- This cheatsheet[^] might provide some valuable tips on optimizing. It made me think twice about progressbars
I are Troll
|
|
|
|
|
I have mailed you this time instead of replying here. Given my id too.
|
|
|
|
|
I do not believe that there is something built into the framework. There may be something in the big wide internet, but I'm not sure what I'd use to look it up.
Are the items all indexed concsecutively? If so, you will probably want to look for something that implements IList instead of IDictionary . The reason other people suggested Dictionary is probably because you said your list had "keys" and "values" implying possible non-consecutive indexes.
Making such a collection yourself is not that hard. I put together a sample of how I would do it. It turned out to ~400 lines, most of which were boilerplate. The Tuple class from .NET 4.0 would be helpful here, but you could create one yourself pretty easily. My sample class definition was:
public class DeltaCollection<T1, T2, T3> :
IList,
IList<Tuple<T1, T2, T3>>,
IList<Tuple<T1?, T2?, T3?>>
where T1 : struct, T2 : struct, T3 : struct
(I did it in VB, so I may have messed up the generic constraint syntax.)
Update
I played around some more and was able to get it down to ~200 lines +15-30 lines per tuple size (number of values per row) you want to support. Again, this would be benefited greatly by .NET 4.0's Tuple class, which had to be reimplemented to use in my class now. The main difference between this version and the original is that the Item property and foreach enumerator will now return Tuple<T1?, T2?, T3?> instead of Tuple<T1, T2, T3> .
modified on Wednesday, December 16, 2009 11:04 PM
|
|
|
|
|
I am working on 3.5 sp1. So, can't use Tuple for now.
Please read the comments in the modified question.
|
|
|
|
|
Well, you could make your own Tuple if you really wanted, but it looks like you already have a similar class to use instead.
Like Eddy said, for your situation, you will have to loop somewhere. Either you have to keep a continuous list with the calculated values for all indexes up to the highest one, which implies a loop on every item insert/change, or you have to perform a search for the next lowest item and calculate its values on item access. It sounds like you want array-like access performance, so you will probably want to take the first option of calculating the values on insert (as Eddy suggested).
If you will be accessing the items in sequence and not randomly indexing, you could get the best of both worlds by writing an iterator that keeps a "current value" and "index" to keep the calculation time minimal.
A quick search did not find any existing implementation for such a collection, but it should not be that difficult to roll your own (especially since you know exactly what features you want).
|
|
|
|
|
Gideon Engelberth wrote: Like Eddy said, for your situation, you will have to loop somewhere.
Yes. I am already doing that. That is how it being done currently even in the class. options are obvious that either at the insert or at the lookup time, looping is inevitable.
The point it that I want to achieve performance boost by some better technique instead of obvious looping.
hashtables improve the efficiency of dictionary. and similarly datatable uses indexing techniques. A datatable like structure could be created by using a simple dictionary also.
Since I have a basic functionality need, I only wonder if there could be very basic. Less the number of lines, faster the code. I am already working on reducing lines further by creating internal classes. Done most of it already.
I will try and refine that and may be post here later. I owe a lot to CP already.
Seems like there is nothing to save me here right now. In any case, thanks a lot guys.
|
|
|
|
|
Namaste Sri Som,
[edit : made array of "current value" nullable integers private and non-static after realizing that by making the array static you could only have one usable instance of the class : please remember this code was written in less than five minutes "off top of my head" : welcome any suggestions to improve it ! ]
Here's an idea off the "top of my head" :
1. use a class inheriting from a generic dictionary (we'll use an int [non-nullable] here for a key, but, of course, you could use something else as a key)
2. for the value part of each dictionary entry use a List of nullable ints List<int?> were going to make use of nulllable here to simulate "missing" data entries.
3. use an array of nullable ints inside the dictionary to track the current values you may need to replace "missing values" with : that gets us around the problem that a .NET Dictionary has no inherent "ordinality" you can rely on.
public class keyedNullableIntTable : Dictionary<int, List<int?>>
{
private int?[] referenceValues = new int?[3];
public void Add(int theKey, List<int?> theValues)
{
for (int i = 0; i < 3; i++)
{
if (theValues[i] == null)
{
if (referenceValues[i] != null)
{
theValues[i] = referenceValues[i];
}
}
else
{
referenceValues[i] = theValues[i];
}
}
base.Add(theKey, theValues);
}
}
Here's a sample test : assumes you have a form with a 'button1 on it to call the eventhandler :
private void button1_Click(object sender, EventArgs e)
{
keyedNullableIntTable t1 = new keyedNullableIntTable();
t1.Add(1, new List<int?> { 100,null,300 });
t1.Add(2, new List<int?> { null, null, 300 });
t1.Add(3, new List<int?> { 222, 333, 444 });
t1.Add(4, new List<int?> { 111, null, null });
t1.Add(5, new List<int?> { null, null, null });
foreach (var theEntry in t1)
{
Console.Write("key = " + theEntry.Key + "\tlist = ");
foreach (var listValue in theEntry.Value)
{
Console.Write(listValue + " : ");
}
Console.WriteLine();
}
}
I bet there's some really elegant way you could use Linq to get this done, too, but I am only a larva when it comes to Linq Hope I understood your question, and this is useful.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
modified on Thursday, December 17, 2009 1:35 AM
|
|
|
|
|
This only solves the problem of creating the dictionary. Question is for retrieving them back.
I have added my comments to the question itself. There are some more areas to look at.
Please give it a read.
And yes. thanks for the attempt.
|
|
|
|
|
Namaste Suits just fine. However, you could do with a Hello too. (We are too used to "Hello World" anyways)
|
|
|
|
|
Som Shekhar wrote:
"I have added my comments to the question itself. There are some more areas to look at."
Hi Som,
Have edited the first code example to make the internal list<int?> of "current values to replace with if incoming item# is null" private and not static.
Will be able to review your comments later tonight (I live at GMT +7 by the way) to try to understand what you mean by "retrieving them back" : isn't the test example I show in the code ... where the keys and list values are being read out in a foreach loop ... and printed to the console ... an example of retrieving back the values ?
If I want the 3rd. item in the List<int?> in the dictionary t1 which is accessed by the key #4 : and I access it via :
t1[4][2]
Isn't that retrieving ?
Namaste, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
I guess you sent me a message. I didn't see it here though..
What I was looking for was a framework implementation to sort my issue. I have done something on my own already and it works currently. Just a speed improvement was needed.
I have already worked on multithreading and some decent work is already done... so only thing better would be a root level work.
|
|
|
|
|
in my c# app i have a socket communicating with a socket that is developed using java. i make a connection with it (long term)and stay idle for more than 3 hrs. but suddenly my connection goes down with out noticing any of the apps.
in java side it has set the connection timeout, in c# side it is not set(i didn't find an easy way to set it).both sides have set the "sokeepalive" to true.
any idea why this happens,
and also like to know when the "sokeepalive" is set is sends probes to check if the client is up, at that time if the timeout is set does this reset the timeout.
|
|
|
|
|
The TcpClient and the Socket classes both have the SendTimeout. Setting these will let you specify the timeouts you want to use.
I am really not surce how the sokeepalive works, so I can't help you on this, but I will at least try to create a keep-alive command as part of my communication protocol and call it manually.
|
|
|
|
|
Hello Everyone,
I have created a desktop application in VisualStudio2008 using C#. Now I am creating setup project for this application.
I am really very new for the setup and deployment project so I googled few documents and got some idea about it, but still I am unable to fix my issue.
Basically I want this application should install on users profile on stratup programs, so whenever users logs in application should start automatically.
I really appreciate if you guys can provide me solution for my small problem.
I am creating setup in VS2008.
Thanks.
|
|
|
|
|
- Right click the installer project in Solution View, select View --> File System
- Right Click "File System on Target Machine" --> Add Special Folder --> User's Startup Folder
- Select the Application Folder, Right click the Primary output & Create Shortcut.
- Move the shortcut to the Startup folder created in Step 2.
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
maybe instead of installer feature make it an application setting..
using registry for example:
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
key.SetValue("%app_name%", Application.ExecutablePath);
key.Close();
life is study!!!
|
|
|
|
|
|
In what sense is it not solved yet? You are going to have to give us all a clue!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
My setup should create a copy of "exe" here..
"Users\Guest\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup\My.exe"
so when users logon to his system then it will run automatically...
If there are anyother way to do that please let me know.
|
|
|
|
|