473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strange Exception in default Hashtable constructor

While running some long term tests on our Broadcast SDK one of our
thread dropped out because an exception had been thrown:

Exception: System.ArgumentOutOfRangeException
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collections.Hashtable..ctor(Int32 capacity, Single
loadFactor, IHashCodeProvider hcp, IComparer comparer)
at System.Collections.Hashtable..ctor()
at Codestuff.Harthill.Sources.BaseSource.ReadHeaders( Stream s)
at Codestuff.Harthill.Sources.BaseSource.ReadJpeg(Str eam str, Byte[]
boundaryBytes)
at Codestuff.Harthill.Sources.LiveSource.VideoStreamP roc()

Now, correct me if I'm wrong but surely if I'm calling the default
constructor on such a common Framework class, I shouldn't expect to get
an Argument exception...

Has anyone else seen this or know what could be causing it?

Dec 5 '05 #1
9 4620
Nick,

When you use a default hashtable constructor, it assumes a load factor
of 1. However, because it uses a float for that, it might not be exactly 1
(even though it is baked into the code as 1).

This could be the result of your exception. Unfortunately, reproducing
it consistently will be extremely difficult. This is one of the dangers of
using floats...

Perhaps what you could do is create a wrapper which will catch that
exception, and retry the creation of the hashtable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nick Vaughan" <ni**@codestuff.net> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
While running some long term tests on our Broadcast SDK one of our
thread dropped out because an exception had been thrown:

Exception: System.ArgumentOutOfRangeException
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collections.Hashtable..ctor(Int32 capacity, Single
loadFactor, IHashCodeProvider hcp, IComparer comparer)
at System.Collections.Hashtable..ctor()
at Codestuff.Harthill.Sources.BaseSource.ReadHeaders( Stream s)
at Codestuff.Harthill.Sources.BaseSource.ReadJpeg(Str eam str, Byte[]
boundaryBytes)
at Codestuff.Harthill.Sources.LiveSource.VideoStreamP roc()

Now, correct me if I'm wrong but surely if I'm calling the default
constructor on such a common Framework class, I shouldn't expect to get
an Argument exception...

Has anyone else seen this or know what could be causing it?

Dec 5 '05 #2
Hi Nicholas,

Thanks for your reply.

How can a float which is 1.0 not always be 1.0? I would have though
it's a constant value.

Are you suggesting that once in a while, this constructor is just going
to fling an exception? That sounds like quite a serious issue doesn't
it?

Could it be that the default constructor tries to modify the loadfactor
based on the amount of available memory?

Am I required to put a try-catch block around every call to 'new
Hashtable( )' ??

Cheers,

Nick.

Dec 5 '05 #3
Nicholas Paldino [.NET/C# MVP] wrote:
When you use a default hashtable constructor, it assumes a load factor
of 1. However, because it uses a float for that, it might not be exactly 1
(even though it is baked into the code as 1).


If it's baked into the code as 1, it should be exactly 1. 1 is exactly
representable in all the various floating point formats .NET has.

I can't think of any floating point conversion that would corrupt that,
or give a false comparison with another value of exactly 1.

This is very odd...

Jon

Dec 5 '05 #4
Jon,

How about a cast from double to float?

When looking at the code in reflector, it's the only thing I could think
of that would cause this.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Nicholas Paldino [.NET/C# MVP] wrote:
When you use a default hashtable constructor, it assumes a load
factor
of 1. However, because it uses a float for that, it might not be exactly
1
(even though it is baked into the code as 1).


If it's baked into the code as 1, it should be exactly 1. 1 is exactly
representable in all the various floating point formats .NET has.

I can't think of any floating point conversion that would corrupt that,
or give a false comparison with another value of exactly 1.

This is very odd...

Jon

Dec 5 '05 #5
Nicholas Paldino [.NET/C# MVP] wrote:
How about a cast from double to float?
Certainly wouldn't change 1.0 to anything else, because it's exactly
representable in both forms. At least, it would only break things if
something was seriously broken in the conversion :)

(None of the 80-bit to 32/64-bit conversions should break 1.0 either.
It's one of the simplest bit patterns for floating point numbers that
you can get...)
When looking at the code in reflector, it's the only thing I could think
of that would cause this.


That's reasonable - I just can't see how it would possibly fail.

I suspect either a hardware failure or a problem deep inside the CLR...

Jon

Dec 5 '05 #6
Well, it just happened again this evening:

Exception: System.ArgumentOutOfRangeException
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collections.Hashtable..ctor(Int32 capacity, Single
loadFactor, IHashCodeProvider hcp, IComparer comparer)
at System.Collections.Hashtable..ctor()
at Codestuff.Harthill.Sources.BaseSource.ReadHeaders( Stream s)
at Codestuff.Harthill.Sources.BaseSource.ReadJpeg(Str eam str, Byte[]
boundaryBytes)
at Codestuff.Harthill.Sources.LiveSource.VideoStreamP roc()

To be honest, I'm going to refactor this code anyway as I don't really
like the idea of create a new hashtable 30 times a second!! However,
its an interesting bug with the framework I think. Its unlikely to be
hardware as it has happened on 2 separate and quite different machines.

Hopefully someone will be able to track this one down and fix it!!

Thanks for your responses people.

Nick.

Dec 6 '05 #7
This is a long shot, but does it happen only on one particular machine?
Have you tried running a utility to thrash that machine's memory to
make sure that it's OK? One of the guys in my office swears that these
oddball bugs are occasionally the result of bad memory.

Dec 6 '05 #8
Nick Vaughan wrote:
Well, it just happened again this evening:

Exception: System.ArgumentOutOfRangeException
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collections.Hashtable..ctor(Int32 capacity, Single
loadFactor, IHashCodeProvider hcp, IComparer comparer)
at System.Collections.Hashtable..ctor()
at Codestuff.Harthill.Sources.BaseSource.ReadHeaders( Stream s)
at Codestuff.Harthill.Sources.BaseSource.ReadJpeg(Str eam str, Byte[]
boundaryBytes)
at Codestuff.Harthill.Sources.LiveSource.VideoStreamP roc()

To be honest, I'm going to refactor this code anyway as I don't really
like the idea of create a new hashtable 30 times a second!!
Well, I wouldn't worry about that. 30 new hashtables in a second is
barely going to catc your computer's attention. I very quick
micro-benchmark I just wrote showed my desktop being able to create
about 8 *million* new hashtables in a second. Go for the simplest code
which works and which doesn't give you a *definite* performance
problem.
However, its an interesting bug with the framework I think. Its unlikely to be
hardware as it has happened on 2 separate and quite different machines.


This is an odd suggestion, but are these machines by any chance using
the same anti-virus software? Try disabling the AV software, reboot,
and try again. I've seen some AV software changing the floating point
mode of a computer, and that can have some odd effects. I can't see why
it would be a problem here, but it's possible. If that's not it, could
you tell us anything else which the two computers have in common?

Jon

Dec 6 '05 #9
They are both running the same AV software, I'll run the tests again
tonight with it turned off and report back. There does seem to be
something happening with the network around the time of the exception
being thrown so this could tie in.

Cheers,

nick.

Dec 6 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
4
by: alkee.na | last post by:
Hey, Here's a sample code you can easily guess the result. <result 1> #include <iostream> using namespace std; class AA { public: AA() { cout<<"AA();"<<endl; }
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
11
by: Lloyd Dupont | last post by:
(not I use 2.0, so new return a "normal" pointer and gcnew return a managed one, my question below regarding new concern plain standart C++ allocator) - if I use the default new operator, are all...
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
12
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
3
by: hiddenhippo | last post by:
Hi, I have a class which contains all my constant values such as; public static readonly string strStringOps = {"Equals","Not Equals","Contains"}; The above nicely assigns the values into...
10
by: Rahul | last post by:
Hi Everyone, I have the following exception class, class E1 { }; class E2 {
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.