|
But no matter how you code it, const or literal, it must be an object at run-time!
The compiler arranges for it to always be the same object.
This is from the c# spec document:
For instance, the output produced by
class Test
{
static void Main() {
object a = "hello";
object b = "hello";
System.Console.WriteLine(a == b);
}
} is True because the two literals refer to the same string instance.
|
|
|
|
|
Well no, if you stick it in there as a literal, it's only stored once, in the code.
Unless you're saying...
Console.Writeln("Hello World");
...creates a string object in memory?
Your IF is true above because you used the equivalence operator, which compares the values, not the pointers.
|
|
|
|
|
|
Regarding == of the strings, the same result (true ) is displayed if the comparison is changed to: object.ReferenceEquals(a,b)
They really are the same object.
|
|
|
|
|
It's probably personal. I prefer option 2, because it does not allow for confusion and keys rarely or never change name.
|
|
|
|
|
There are a number of issues here, when speaking about a generic answer rather than one strictly limited to the examples given, with one potentially important one so far not mentioned: the assignment will happen at different times.
In your first example, SettingValue is assigned after all base constructors have been executed. In your second example, which uses field initialisation, SettingValue is assigned before any base constructors have been executed.
This may affect what exceptions are thrown on construction errors. For instance, a ConfigurationErrorsException will be thrown if the value is not found. In the first example, you can catch this in the constructor and set a default, or give a more detailed exception. In the second example, you can't, and will have to rely on it being caught outside the class.
And if a base constructor would also throw an exception, in your first example this is what will be thrown, while in the second example it's the ConfigurationErrorsException that will be thrown.
|
|
|
|
|
Orjan Westin wrote: a ConfigurationErrorsException will be thrown if the value is not found
Not in the AppSettings section; if the specified key doesn't exist, it will return null .
However, you can get a ConfigurationErrorsException if the configuration file is corrupt.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh, I wasn't aware of that. Thanks.
|
|
|
|
|
Thanks! This is what I'm looking for. I didn't think about the order of things, that might be important. Also thanks for giving me the names of the processes, I had never heard "field initialization" before.
|
|
|
|
|
Option 1 because if it fails then the cause of the failure is less likely to be confusing.
And yes the code can fail.
|
|
|
|
|
Any code can fail, but if this fails, it's a fatal error and if the application blows up, that's fine.
|
|
|
|
|
Hi All;
I have a large dataset stored in a CSV file (about 40,000 Rows and 10,000 Columns). I need to load it into a C# Windows application. So, any idea to do this. I tried different code, but some are able to loao 40,000 R * 255 C, and other codes are able to load 5,000 R and 10,000 C.
Thanks
losan1985
|
|
|
|
|
It's probably going to take rolling your own custom class to hold it all. I don't know of anything "off-the-shelf" that will hold 10,000 columns. Frankly, I've never even HEARD of such a wide CSV file ever being used.
It shouldn't be very hard at all to create a List<list<int>> or whatever your item data type is. Basically, a List of List of Integers.
|
|
|
|
|
You probably can't load it all at once (at least in a 32-bit OS). 40,000 x 10,000 = 400,000,000 bytes if each cell is 1 byte. If you assume an average of 16 bytes (since you didn't say) per cell, thats 6,400,000,000 bytes = 5GB of data. You only have 2GB of address space for your application. You can do it on a 64-bit OS though.
With that being said, I doubt you really need 40,000 x 10,000 cells loaded in memory at once. What is a person going to do with all that data?
You might want to consider loading only the portion you need.
|
|
|
|
|
What is your actual requirement? You are loading this data for a reason. What is that reason? For instance, are you performing some calculation on certain columns? By breaking down your requirements, we can work out a practical solution.
|
|
|
|
|
yes, this may solve your problem....
|
|
|
|
|
As POH has said your design has to be wrong for this to be a valid requirement. Go back and look at how the CSV was created, why does it require 10k columns (what a ridiculous number). Can your source break it up into more swallowable chunks. Do you need all 10k columns.
Can you load and process 1 row at a time, presumably you want to dump this into some more reasonable format.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You'll need to build in a sort of paging mechanism that only loads that part that is shown on the screen.
|
|
|
|
|
As Sledgehammer01 says, that's an unreasonably large amount of data for most purposes. It's 400 million cells and so you're talking about GB of memory, depending on exactly what's in there. What do you want to do with this dataset? You almost certainly want a load-on-demand adapter of some kind, so you can run through the data without actually having it all in memory at once.
This library is rather good; I used it in a real application (though not dealing with massive datasets) without problem.
|
|
|
|
|
Hi losan,
I found your post very interesting because I've never encountered a data set that large. Are you trying to analyze that data? If so, I may be able to help.
I have a product (www.patternscope.com) that finds patterns in extremely large data sets. I think your data set would be good for stress-testing the application, and it fits perfectly with two planned developments:
1. Reading CSV data (currently it only reads databases through ODBC, or flat files), and
2. Making a C#-callable API that you could use in your C# application to handle that much data (e.g. queries, retrieval, and analysis).
My product extracts the patterns that comprise the raw data. These patterns are a fraction of the size of the original raw data, so they fit entirely into memory, even when the raw data is larger than the memory available.
The patterns have the same information content as the raw data, so can be processed (e.g. queries or analysis) many times faster.
If you could give me a copy of your data set, I could give you a free copy of PatternScope (after I adapt it for reading CSV data) which you could use to analyze the data, followed by a DLL you could call from C# for processing the data in your program.
What does this data represent?
|
|
|
|
|
Hi;
Here is a link for the Dataset
"www.dropbox.com/s/een9zlqce4vqqrl/ProjectData3.csv"
What I need to do is to apply the collaborative filtering algorithms in the dataset. The data set is about Tweets, who is going to retweet from another person.
Thanks
losan1985
|
|
|
|
|
Thanks. When I've adapted PatternScope for comma-separated values, I'll send you a copy. Collaborative filtering looks interesting.
|
|
|
|
|
My requirement is Capturing Video from web cam and saving it in .avi format. I am currently using DirectShowNet Library, But the captured video size is too big. For 10 sec video it takes 70 MB storage size. I have tried other web cam libraries but nothing works.
I have tried AForge, EMGU, DirectX and some other libraries, but the problem still exists (video size is too big).
If you have ever worked on this type of problem, please help me or suggest me for some other libraries.
___ ___ ___
|__ |_| |\ | | |_| \ /
__| | | | \| |__| | | /
|
|
|
|
|
Raw Video Data has it's cost (that's the big size on the disk it eats ) You'll either need to a) reduce the resolution you're recording a video or b) encode the video with a codec to reduce the size.
I haven't done something like that programatically myself yet. However already used some converters which are available for free on the internet to convert the videos. (As far as I remember you should be even able to use the windows live movie maker )
|
|
|
|
|
Yes, I think you are right. I need to encode/compress the RAW Video data into proper format.
Can you please suggest any library for doing the same. Thanks
___ ___ ___
|__ |_| |\ | | |_| \ /
__| | | | \| |__| | | /
|
|
|
|