|
Luc Pattyn wrote:
yep, your SpecialDictionary.GetEnumerator() would behave quite different from
List.GetEnumerator() and others.
What sort of code would rely upon having a collection throw an exception on the next iteration of an enumerator following a change? To my mind, it would be reasonable to require an exception if the enumerator is incapable of functioning without malfunction, but if the enumerator can function without malfunction, why shouldn't it?
Actually, I find the design of the collection classes to be a pretty incredible mish-mosh. The Collection type doesn't mind deletion during enumeration; in a lot of ways it's a nice class, but it doesn't provide generic support, it isn't compatible with anything else, and seems to be deprecated despite its reasonable performance and unique abilities. As for other classes, HashTable offers better performance than Dictionary, but it's not compatible. It's useful that an iDictionary can return the Keys and Values properties, but they require absurdly broad interfaces. Having an iDictionary.Values support iEnumerable (which returns values rather than key-value pairs) is useful. But having it support an Add method? What is a Dictionary supposed to do if one attempts someDictionary.Values.Add(whatever)? The semantics seem totally nonsensical to me.
Incidentally, I also find it unfortunate that Microsoft didn't provide a WeakDelegate type. Adding some events to collections would make them more powerful, but unfortunately it would also create substantial risks of memory leakage.
|
|
|
|
|
Hi,
1.
Code using GetEnumerator might go without locks and trust an Exception is thrown when the collection gets changed somehow (e.g. by another thread, possibly by someone else's code). So there is some ease of use in such a case (as there is for the author of the collection's enumerator itself).
2.
The collection classes are not perfect indeed. This is partly due to the fact that some of them got invented before C# offered generics. Several 1.x methods/properties return arrays and special kinds of lists (e.g. TabControl.TabPages) where a simple List< T> would do, and would be easier to handle. Also I am not fond about the choosen names (as in SortedList which is a Dictionary, not a List).
3.
You are right about the weak delegate stuff. I trust you've read this article[^] on the subject?
|
|
|
|
|
Luc Pattyn wrote: 1. Code using GetEnumerator might go without locks and trust an Exception is thrown when the collection gets changed somehow (e.g. by another thread, possibly by someone else's code). So there is some ease of use in such a case (as there is for the author of the collection's enumerator itself).
Do any of Microsoft's collection objects guarantee that they will throw exceptions if they are being read by one thread while another thread modifies them? While I expect that would often occur, it's dangerous to make unfounded assumptions regarding thread safety.
2. The collection classes are not perfect indeed. This is partly due to the fact that some of them got invented before C# offered generics. Several 1.x methods/properties return arrays and special kinds of lists (e.g. TabControl.TabPages) where a simple List< T> would do, and would be easier to handle. Also I am not fond about the choosen names (as in SortedList which is a Dictionary, not a List).
I wonder why there isn't a more modern version of the VisualBasic.Collection class which includes all its features?
3. You are right about the weak delegate stuff. I trust you've read this article on the subject?
I have. I'm not sure I totally trust the concept of dynamically-generated code, but the performance seems good. I also came up with my own variation which unfortunately doesn't work with standard event-based code but has a few benefits of its own. I haven't benchmarked it, though.
An event subscriber must support interface iDelegLink(of T) for some type T; to send an event, a publisher invokes sendEvent(of T)(data as T) which ends up calling Execute(sender as Object, tag as Object, data as T) as Boolean; invocation is done by performing a TryCast on a WeakReference to turn it into an iDelegLink(of T) whose Execute method is then called. If the Execute function returns true, the subscription will be canceled; otherwise it will remain.
Unlike the normal event system using delegates, mine performs thread-safe lock-free event subscription and unsubscription in constant time (an event subscriber must either keep a subscription object returned when it subscribed to the event, or it must remain subscribed until the next time the event is called, whereupon it can unsubscribe by returning True.)
|
|
|
|
|
Hi,
supercat9 wrote: Do any of Microsoft's collection objects guarantee that they will throw exceptions if ...
No, there is no thread safety in general. However GetEnumerator returns an IEnumerable and that promises an InvalidOperationException when the collection gets modified (see Current and MoveNext). I trust that works fine even when two threads are involved; it would be my guess they have some kind of generation number or so that gets compared on every invocation of Current/MoveNext.
supercat9 wrote: I wonder why there isn't a more modern version of the VisualBasic.Collection class which includes all its features?
I don't know. In fact I was unaware of Collection class until you mentioned it earlier. There are several classes marked "Visual Basic" and I would guess they mainly exist for compatibility or easier upgradability reasons where old VB code is involved??
supercat9 wrote: mine performs thread-safe lock-free event subscription and unsubscription in constant time
Sounds like a good subject for a nice article. Any plans?
|
|
|
|
|
Luc Pattyn wrote: No, there is no thread safety in general. However GetEnumerator returns an IEnumerable and that promises an InvalidOperationException when the collection gets modified (see Current and MoveNext). I trust that works fine even when two threads are involved; it would be my guess they have some kind of generation number or so that gets compared on every invocation of Current/MoveNext.
The Collection object returns an iEnumerator that does not throw an exception if the underlying collection is modified.
Luc Pattyn wrote: I don't know. In fact I was unaware of Collection class until you mentioned it earlier. There are several classes marked "Visual Basic" and I would guess they mainly exist for compatibility or easier upgradability reasons where old VB code is involved??
The VB 'collection' object allows modification during enumeration, which is a useful feature. Why can't Microsoft offer any non "visualbasic" key-value-pair object which does likewise? Any code which relies upon an iEnumerable to throw an exception if the underlying structure is modified will fail when passed the enumerator from a VisualBasic.Collection.
Luc Pattyn wrote:
Sounds like a good subject for a nice article. Any plans?
Dunno. I'm hardly a VB expert. I don't know whether people would consider it worthwhile or stupid.
modified on Sunday, November 9, 2008 9:39 PM
|
|
|
|
|
Twice as slow as a well-optimised C version is a little surprising, but not overly. The performance of the JIT certainly isn't on-par with the better compilers yet.
Searching for an integer in a large array is more a sign of bad data structure design. 40us vs 20us is fairly irrelevant when its fairly obvious you have some O(n) complexity that you want removed.
|
|
|
|
|
Mark Churchill wrote: Searching for an integer in a large array is more a sign of bad data structure design. 40us vs 20us is fairly irrelevant when its fairly obvious you have some O(n) complexity that you want removed.
O(n) algorithms are good for small data sets; poor for larger ones. What constitutes "small" may change with time. Hash tables can give very nice performance, but they can waste a lot of memory with small data sets. I was trying to decide whether my data sets would be large enough to require a hash table; it seems they are.
|
|
|
|
|
Hello and please forgive me if this is not the right place to inquire, I am looking for a place to post a job for a .net developer who is not too senior, where could you recommend that i post this job? You can reach me at phyllis@panologic.com.
Job:
Software Engineer Windows Applications
Pano Logic is a venture-backed startup leading the Desktop Virtualization revolution. We are looking for an exceptional software engineer to build applications, user interfaces, and installers that are the "face" of Pano Logic's desktop virtual machine software.
• 0-4 years of C++-based application development experience
• Experience building high-quality Windows applications, user interfaces, and installers
• Knowledge of MFC, .NET, and Win32 system APIs
• Knowledge of Windows Installation technologies (Wix, Installshield, MSIs, etc)
• Experience building environments for unit tests, regressions, and nightly builds
• Experience with software build systems for Windows
• Computer Science/Engineering University Degree or equivalent
• Excellent interpersonal, verbal and written communication skills
The following would be an asset:
• Experience with device driver installation through Wix
• Scripting experience (Powershell, Perl, Python, shell scripting)
Please send resume to careers@panologic.com
|
|
|
|
|
|
"...looking for an exceptional software engineer..." with 0-4 years experience?
I read that as "we want somebody to do world-class work for entry-level pay".
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I read that as "we want somebody to do world-class work for entry-level pay".
I read that as a law-suit waiting to happen. In the UK you can no longer request specific numbers of years experience because it could be a round about way of trying to gauge a person's age and ageism is now illegal in a recruitment situation.
|
|
|
|
|
My resume goes all the way back to 1974. I think that makes it kind of obvious that I'm an old f*cker.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Mark Salsbery wrote: we want somebody to do world-class work for entry-level pay
Good luck to the OP to find a sucker.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
There is a job board[^] on this site. You should post there.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
PhyllisM wrote: Hello and please forgive me if this is not the right place to inquire, I am looking for a place to post a job for a .net developer who is not too senior
Well, I'm not sure how you could have missed the big green bar near the top of the site's home page.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I want to create a library for all the sql database operations.All other functions are working, but function for returning sqldatareader doesn't work.When I call this function from my page and try to access returned datareader object >it gives the error reader is closed. What to do???
|
|
|
|
|
No one can help you until you show us the code for returning sqldatareader. However, from the error code I suspect that the connection used by the reader is closed.
|
|
|
|
|
This is thecode in my class
sqlDatareader ExecuteReader(string pStrQuery)
{
sqlDatareader dr;
sqlCommand cmdObj=new sqlCommand(pStrQuery);
try
{
cmdObj.open();
dr=cmdObj.ExecuteReader;
return dr;
}
finally
{
cmdObj.close();
}
}
and this is how I use it:
sqlDataReader dr=obj.ExecuteReader(query);
and here it shows datareader is closed if try to read it.I even tried it without finally block.Not working.I'd appreciate any hep.
|
|
|
|
|
Your problem is that you closed the Reader in the Finally block. Whenever execution leaves the Try block FOR ANY REASON, the code in the Finally block is executed, where you close the Reader.
Remove the code from the Try block and run it again. Your Try block is catching any and all errors and supressing them since you don't have a Catch block reporting the error.
|
|
|
|
|
As you you are using try finally block, the connection is closed so it is impossible to read from the reader as SqlDataReader requires open connection. So just return the reader without closing the connection.
|
|
|
|
|
As the others have commented, you need to remove the close on the connection to return it. You should also ensure that the DataReader closes the connection for you. One method of doing this is to pass in CommandBehavior.CloseConnection as a parameter to ExecuteReader .
|
|
|
|
|
Hey Pete,
Thanks for your post. Never realized that the CommandBehavior.CloseConnection enum existed. Very nice tip.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
HI,
Can any one guide me how to run commands from a .Net Application developed in C# at Command prompt(i.E C:\>)
Any links on it would also be helpful
|
|
|
|
|
Hi,
try Process.Start("cmd.exe", args)
If that does not do what you want, have a look at ProcessStartInfo class and use Process.Start(psi)
|
|
|
|
|