I also share a C # INI action class

Source: Internet
Author: User

Just read an @ Yunfeifei about the regular-based INI helper class article: Http://www.cnblogs.com/yunfeifei/p/4081977.html, the author is good. Also see the comment Office has an address: https://devlib.codeplex.com/SourceControl/latest#main/product/Codes/DevLib.Configuration/ IniEntry.cs is also a few convenient encapsulation classes based on INI. The latter is obviously more versatile than the former, the former is simple to use, very convenient. But the overall is very good. I learn shallow, beg not to spray! ! ~

After I thought about it, why not thousand INI helper class myself? As a result, the INI class has the following advantages:

1. Speed up access.

I'm really a man who likes to reinvent the wheel because I have a lot of spare time. There is some emphasis on this programming infrastructure. Knocking code can save the province. Many people may say that the INI operation is simply too simple, and there is no need to reinvent the wheel. You know, other people write not necessarily good performance. Microsoft provides the Win32API "writeprivateprofilestring,getprivateprofilestring" such functions, looks very convenient, but in fact very chicken.

Because GetPrivateProfileString is read once to access the disk, if you want to read a lot of key value pairs, then efficiency simply can't bear to look straight!

System.Diagnostics.Stopwatch Stopwatch =NewSystem.Diagnostics.Stopwatch (); stringPath =@"D:\Users\Administrator\Documents\SenderRobot\SenderRobot.ini"; Stopwatch.            Start ();  for(inti =0; I <10000; i++) {List<IniStruct> inistructs =ini.readvalues (path);//I use the bulk Read method here intentionally}stringA = stopwatch. Elapsed.tostring ();//the time it took to read the INI class methodstopwatch.            Reset (); Stopwatch.            Start ();  for(inti =0; I <10000; i++) {Util.readinivalue ("should pattern","SSS", path); } stopwatch.            Stop (); stringb = Stopwatch. Elapsed.tostring ();//The time it took for Microsoft's function to read

Make your own changes and compare the efficiency look! I read it once and put all the key-value pairs out and put them in memory. And Microsoft is to read many times to achieve this effect, so the efficiency can be imagined! In this way, if you have a program to load a lot of parameters at startup, you can let the disk live for several years not to say, reading speed is the same feeling!

2. In addition I added the function of the INI annotation to strengthen. Many people in INI directly use Chinese as the key. In this way, your program is not self-descending level, feeling too cottage. In English as a key, not worship OH. This INI class, can not only bulk read the same time to read the comments, but also in the code to write comments to the INI file, this function is afraid of the Microsoft API can not do it.

3.ini auxiliary classes are simple to operate. This class has no threshold for everyone. That's just a couple of functions. There can be statically static access, there is to be instantiated before the operation. Static and convenient one-time operation. Instantiation of access is convenient for frequent operations.

Later, I also can not say more advantages. You can use it if you need it.

There are several ways to save local small batches of data at this time:

1.ini

2.xml

3. Local Database

4. As for the direct use of the text directly ignore it. It's too non-mainstream.

5. The recently popular PROTOBUF

First say INI:

INI is an older way of storing. In the era of Win2000 is already very popular. Quick and easy

XML is later rookie, more standardized. Many occasions can replace INI directly. However, in the case of small programs, INI is definitely the most suitable, in addition to performance considerations, XML format is too strict is one of the reasons.

Local databases are typically used to hold big data. such as the commonly used litesql and so on. Small program, then forget it. There is a time to write the SQL statement that the people have finished writing the whole.

Protobuf is a file transfer format that Google contributes to the open source community, primarily for sending and receiving information over the Internet. Protocol's high efficiency is 100 times times faster than XML, supposedly at least as fast as XML. Protocol is a direct binary save, the rules are relatively simple, so the parsing speed is bound to be much faster than XML, but also more traffic!

In fact, there is a large company developed coding format, is similar to Protobuf. Called Unistruct (unipacket) official no external code. Just from the reverse of its product. This format is also very compact. Transmission is also very handy.

Well, not much to say, for everyone to pass the C # class, I hope friends have help!

Accessories: Http://files.cnblogs.com/uu102/Ini.rar

I also share a C # INI action class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.