|
AndrusM wrote: You wrote that this code modifies same collection inside foreach loop which is not allowed.
.NET does not throw exception for this code.
So it is .NET bug, isn't it ?
No, it's not a compile time error. There is no way for the compiler to know that the method called "Remove" removes items from the collection. You could call the very same method "Jaxtapose". The name of the method doesn't tell the compiler anything other than "this is a name". The compiler cannot tell what the code inside the method does.
It WILL throw a run-time exception though.
|
|
|
|
|
No, it will *not* cause run time exception in .NET 2 and 3.5.
It removes all comment from XML.
So my question was: Is this .NET but that this code does not cause run-time exception ?
Andrus
|
|
|
|
|
I wasn't talking about your code. I was talking about what the other person said about what should be a "bug". There are a few exceptions to the rule. It would appear that you have found one of them.
|
|
|
|
|
This cCode removes iterated item from collection inside foreach loop.
C# clearly does not allow to change iterated collection in foreach body.
This should cause exception.
So why do you think that this is exception of this rule and should be allowed ?
Andrus
|
|
|
|
|
Not that last snippet you posted, it's enumerating one collection and removing from the other, so there's no problem.
|
|
|
|
|
He's right. The snippet you posted isn't doing anything to the collection being enumerated. The exception to the rule...
|
|
|
|
|
Hi,
I have been making a tuning program for instruments, the idea being you play, a guitar say, into the mic and it tells you what note you are playing. It pretty much works, but I am getting strange readings. When nothing is being played, the mic is even muted, I get a reading of either 50 or 125 Hz. These values also pop up a lot when I am playing the guitar into it. I can't think where these phantom sounds are coming from and was wondering if anyone had an idea.
Cheers
|
|
|
|
|
A/D are notorious for bad readings and the right combination of filters usually helps.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
The 50Hz is likely the mains frequency you are picking up somehow; I am not sure about
the 125Hz, are you using a CRT display?
try turning off everything you don't need, switch to a battery-powered notebook (no mains,
no CRT), go outside if possible, doing so you might be able to pinpoint the ghosts
that haunt you.
I guess your audio input is using some automatic volume control; if at all possible you
may want to switch it off or reduce its range (i.e. set a minimum required level).
BTW: I would not blame C# for this.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Cosmic background microwave radiation, from the Big Bang.
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Hertz was not even born then, was he?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Was meant to be a joke
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Maybe I figured that
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Well I got the joke. Good one too!
BDF
|
|
|
|
|
Hi,
I am trying to install a windows application using clickonce.
The application can be installed on several machines successfully but NOT on one machine.
It gives an error on .manifest file not being able to be downloaded. It seems to be looking at the C drive.
If it makes any difference I have included it below.
PLATFORM VERSION INFO
Windows : 5.1.2600.131072 (Win32NT)
Common Language Runtime : 2.0.50727.190
System.Deployment.dll : 2.0.50727.42 (RTM.050727-4200)
mscorwks.dll : 2.0.50727.190 (QFE.050727-1900)
dfdll.dll : 2.0.50727.42 (RTM.050727-4200)
dfshim.dll : 2.0.50727.42 (RTM.050727-4200)
SOURCES
Deployment url : file:///C:/Documents%20and%20Settings/nguyent/Desktop/PricingAnalytics.application
IDENTITIES
Deployment Identity : PricingAnalytics.application, Version=1.0.0.11, Culture=neutral, PublicKeyToken=345994c31edbcaf8, processorArchitecture=msil
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\Documents and Settings\nguyent\Desktop\PricingAnalytics.application resulted in exception. Following failure messages were detected:
+ Downloading file:///C:/Documents and Settings/nguyent/Desktop/PricingAnalytics_1_0_0_11/PricingAnalytics.exe.manifest did not succeed.
+ Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
+ Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
+ Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [29/11/2007 15:51:51] : Activation of C:\Documents and Settings\nguyent\Desktop\PricingAnalytics.application has started.
* [29/11/2007 15:51:51] : Processing of deployment manifest has successfully completed.
* [29/11/2007 15:51:51] : Installation of the application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [29/11/2007 15:51:51] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading file:///C:/Documents and Settings/nguyent/Desktop/PricingAnalytics_1_0_0_11/PricingAnalytics.exe.manifest did not succeed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, IDownloadNotification notification, DownloadOptions options, Uri& appSourceUri, String& appManifestPath)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.Net.WebException
- Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
- Source: System
- Stack trace:
at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.FileWebRequest.GetResponse()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
--- Inner Exception ---
System.Net.WebException
- Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
- Source: System
- Stack trace:
at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
at System.Net.FileWebRequest.WrappedGetResponseCallback(Object state)
--- Inner Exception ---
System.IO.DirectoryNotFoundException
- Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
- Source: mscorlib
- Stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
|
|
|
|
|
Does anyone know if LINQ to SQL lets you map interface types to tables? I want to dynamically generate my classes at runtime, and the mapping scheme only seems to work with a statically-compiled class heirarchy. Has anyone had any luck with this?
|
|
|
|
|
Hello,
Yes, you may generate your classes at runtime and thereafter map the objects to the interface. Instead of using a designer tool like “Linq to SQL Class”, you need to provide the mapping objects on your own.
Here is a link for 10 videos being posted by Mike Taulty which might interest you.
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/04/26/9254.aspx
Best Regards,
Sam Xavier
www.componentone.com
|
|
|
|
|
I am trying to make a method that computes the floor of the base 2 integer log for another integer. My current code is as follows...
public static byte Log2(int val) {
if (val <= 0)
return byte.MaxValue;
byte rval = 0;
while ((val >> rval) > 1)
++rval;
return rval;
}
Is there a better way to do this, like perhaps a binary search algorithm?
Jeff
|
|
|
|
|
Skippums wrote: like perhaps a binary search algorithm?
what? you show a single integer as input, what are you going to search? Who are you?
|
|
|
|
|
For example, the following code, which takes the middle bit of a bound (0 to 32), and attempts to perform the right shift. If the result is 0, I shifted the number too far, so I make my new range 0 to 16, take the new average (8), and try again. If the number is greater than 1 at that point, you modify the lower bound, so now I am shifting 12 bits (average of 8 and 16). Continue this cycle until you find the magic number that makes the resulting shift equal to 1. This is O(log(n)) time, vs. my initial algorithm of O(n). I did some testing of the two, and the second is far faster for randomly generated numbers, but only because most randomly generated are large. When I set the upper bound to 0x1000 (4096) on the random number size, the two algorithms broke even, taking about .95 s to do 0x1000000 (16,777,216) log base 2 method calls. The code is below...
private byte Log2_2(uint val) {
if (val < 1)
return byte.MaxValue;
byte high = sizeof(uint) << 3;
byte low = 0, med = (byte)(high >> 1);
uint tmp = val >> med;
while (tmp != 1) {
if (tmp == 0)
high = med;
else
low = med;
med = (byte)(low + high >> 1);
tmp = val >> med;
}
return med;
}
Jeff
|
|
|
|
|
Hi Jeff,
I currently have a test fixture for your Log2_2 and some of mine;
for the same number of tests they all yield around one second.
First impression is most of the time is spent in the test fixture, not in the log2 method.
May I suggest you measure again with an empty Log2_2 to check by how much the elapsed
time does (not) drop?
Here is one of my tries:
int LP_log2_3(uint val) {
if(val==0) return -1;
int res=0;
if(val>0x0000FFFF) {res+=16;val>>=16;}
if(val>0x000000FF) {res+=8;val>>=8;}
if(val>0x0000000F) {res+=4;val>>=4;}
if(val>0x00000003) {res+=2;val>>=2;}
if(val>1) res++;
return res;
}
I feel another article coming up, comparing C#, C and asm.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Yep, that's what I was looking for. The results of 16,777,216 (0x1000000) calls for randomly generated integers:
Gross Net
1. Linear search: 1542 ms 1091 ms
2. Binary search: 887 ms 436 ms
3. Hardcoded Conditionals: 686 ms 235 ms
4. Control (returns constant): 451 ms 0 ms
That speeds it up by a factor of about 1.85; Thanks!
Jeff
|
|
|
|
|
Are these numbers for debug or release build?
Do you call random generator inside the timed loop or did you store its outcome somehow
beforehand?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
1: Release build.
2: Beforehand
Here is the code...
private Stopwatch sw = new Stopwatch();
private List<uint> m_Nums = new List<uint>(0x1000000);
private List<uint> result1 = new List<uint>(0x1000000);
private List<uint> result2 = new List<uint>(0x1000000);
private List<uint> result3 = new List<uint>(0x1000000);
private List<uint> result4 = new List<uint>(0x1000000);
...
private void button1_Click(object sender, EventArgs e) {
m_Nums.Clear();
result1.Clear();
result2.Clear();
result3.Clear();
result4.Clear();
Random rnd = new Random();
for (int i = 0; i < m_Nums.Capacity; ++i)
m_Nums.Add((uint)rnd.Next());
sw.Start();
foreach (uint num in m_Nums)
result1.Add(Log2_1(num));
sw.Stop();
label1.Text = sw.ElapsedMilliseconds.ToString();
sw.Reset();
}
I even tested it in different orders (ie, calling <3,4,1,2>, etc.), to see if the order those methods were being called effects the time taken by them. They were all reasonably constant regardless of the ordering. Oh yeah, and I attempted to make your Conditional method more extensible in a for loop, but it ended up taking the same time (+-10 ms) as my binary search code. I copied it below...
if (val < 1)
return byte.MaxValue;
int shift = sizeof(uint) << 2;
uint mask = uint.MaxValue >> shift;
int rval = 0;
do {
if (val > mask) {
rval += shift;
val >>= shift;
}
shift >>= 1;
mask >>= shift;
} while (shift > 0);
return (byte)rval;
Jeff
|
|
|
|
|
Thanks for the info.
I guess a big part of the overhead is enumerating the testcases and storing the results
in the List (I did sum+=LP_log2(x); to prevent the optimizer to kick it all)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|