High Performance Solution Ini File Class with MMF
Environment: VC6, WinNT/2k/XP (Having been tested in English/Japanese Win2k/XP)
Special Note: This Unicode Version is full-fledged, while the ANSI version does not support the section header map
Key Technology Used: Memory Map File (MMF), Win32 Memory Management API, Unicode, Data Structure
Applicable Article Category in CodeGuru: Miscellaneous Data Technique
Summary
All is from my previous project, which saves the data of the coordinate, text contents, color, font name, and size information of nearly 30000 dialog controls (listbox, static, edit, and so on) distributed on more than 100 windows. So, the total size of these controls will be at least 10*n Mega bytes and it's not suitable to use the Windows Registry. You see, using a native Ini file Win32 API is terribly impractical because the performance is too low. So, I designed and implemented the following Ini class using MMF; with the pre-allocated buffer and section header map technology, it should be the ultimate solution to the 5-50 Mega byte level Ini File reading and writing situations.
Implementation Description
Pre-allocated buffer
Please refer the following figure:

Click here for a larger image.
When I load the Ini File from the disk to the MMF, depending on the case, I allocate a bigger MMF than the original disk file. When the user just reads the Ini MMF, the Pre-Buffer (see the red bar part) will not be touched. Say, if the user writes more data into the Ini MMF, I can expand the Ini MMF into the Pre-Buffer part. Only when the Pre-Buffer is nearly used up (I call it a Critical Point, see the slim green line), I unload the whole MMF to flush the disk, and load it again with a larger MMF. When measuring carefully in your case, you can get a fairly good performance upgrade with this extra buffer.
Section head position map
When loading an Ini File from the disk file, I make a map of Section Head Pointer and the Section Name. This will take time, but later, when the user searches a section in the end part of the Ini MMF file, it will save considerable time. In my Ini File implementation, I used the CMap MFC class, so this class needs MFC library support. Because my previos project is an MFC-based application, it is reasonable, but to be more universal, I plan to implement it again later with STL.
Special Note with Unicode Ini File:
It is very important to know that Unicode text files have two formats in the Windows OS. And what makes things worse is that Microsoft changed its behavior when it issued Win2000 SP1. In the original Windows 2000, if you open an ANSI text file with Notepad and save it as Unicode text, it just calls the MultiByteToWideChar WinAPI to make changes and save the text; that's it. After you install Win2k SP1 and do the same thing, this time, Notepad adds heading 0xFF FE to the Unicode text. This lack of congruity belabored me a whole day because some member's machine in my team did not upgrade with Win2k SP. (BTW, some specification on the Internet says that in Mac machines the heading will be 0xFE FF.) My Ini File class will check the heading and cope with it.
Usage:
I just want to kiss it (keep it simple, stupid). Unlike some previous Ini File classes on this site, I use just two functions that have the same signature of the Win32 API—GetPrivateProfileString and WritePrivateProfileString to wrap my Ini File class. For example, instead of adding a RemoveSection function, you pass NULL to lpAppName in JXWritePrivateProfileString and you get it. When you want to get all key names in a given section, pass NULL to lpKeyName and get a double NULL ending buffer in lpReturnString. (I include a full-fledged demo project to show this.)
DWORD JXGetPrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpDefault, // default string LPTSTR lpReturnedString, // destination buffer DWORD nSize, // size of destination buffer LPCTSTR lpFileName // initialization file name ) ; BOOL JXWritePrivateProfileString( LPCTSTR lpAppName, // section name LPCTSTR lpKeyName, // key name LPCTSTR lpString, // string to add LPCTSTR lpFileName // initialization file );
Both support ANSI and Unicode versions. Just include JXIniFile.h in your file and add both the JXIniFile.h and .cpp to your project. Check MSDN to get the detailed information because they are the same signature as the Win32 API.
There's just one thing I decided to be different from the Win32 API. When you want to get all the section or key names, and you pass a buffer to JXGetPrivateProfileString, a return value of 0 means your buffer is too small, while the Win32 API will return the buffer size needed. So, when you get the return of 0, just reallocate your buffer and try it until you pass. I did this because the program usually knows the rough size it takes to get the list of section/key names, and a mid-way return 0 in my Ini File class saves time.
Another thing is that I permit the user to unload the Ini MMF at any time by calling
BOOL JXUnloadPrivateProfile();
One possible use of it is that when you debug the program, you can unload the MMF, use a text editor to change some value, and ask your program read the Ini disk file again to see the effect.
Demo
I provide a simple, dialog-based program to show the usage of these two functions. The code to enumerate sections and keys is used to read a Ini file; usually, the program has knowledge of the section name and key name. I enumerate all the section and key names before fetching the value, just to give a worst-case example.

You press the buttons from left to right, generating 100 (by default) sections, each including 100 keys, the value is randomly generated; then, writing the data to disk, reading it back to the right side tree to confirm. The popped-up time message box tells you the total time to read the Ini File and fill the tree. (You can comment the tree-filling code and see the time of reading exclusively.)
Are You Ready To Use It?
- If your application does not use MFC, you have to link with the MFC library because I use CMap to implement the section head map. I am considering implementing it again with STL to make it more universal.
- If your application is not Unicode based, by default you will use its ANSI version. In that case, no section header map support is available. (Just because I have no time and need to use it.) It means the performance is not as good as its Unicode counterpart, but still better than the Win32 API (at least >> 10 times faster). Besides, you can still explicitly call JXGetPrivateProfileStringW and JXWritePrivateProfileStringW.
- Consider your data structure. Instead of using 10 sections each including 1000 values, 100 sections with 100 values will be better.
- Decide your pre-buffer size. I use 1M by default; maybe it is overkill in your case. At least it should keep MMF from reloading in a few seconds in most cases. Actually, if the program just reads the Ini data, you can use 4K (1 memory page).
Acknowledgements
I would like to express my thanks to the following persons and institute: Prof. Moriya Shinji, Human Interaction Lab of Tokyo Denki University, Media Center of Tokyo Denki University, for their academic direction, warm-hearted help, and continuous encouragements to my career life.
Also thanks go to FujiSoftware ABC, Ltd., for the developer position offered, plus their wage.
Downloads
Download demo project - 54 Kb (JXIniFile source file includes <about 4000 lines of code to deal characters one by one>, + exe)Download Demo Exe File Only - 44 Kb (Only exe demo, MFC dynamic linked)
Version History
| Version | Release Date | Features |
| 1.0+ | Nov. 5, 2002 | (Add a demo, finish this article) |
| 1.0 | Sept. 27, 2001 | Heading 0xFF FE handling |

Comments
http://www.oakleysunglassesoutc.com/ bkrmgp
Posted by http://www.oakleysunglassesoutc.com/ Suttonjmm on 03/29/2013 05:45amghd sale,ghd hair straightener,The Sino-Japanese war Yaishan Southern Ocean, Battle of Dadonggou Beiyang Navy hated Japan, coupled with the Tan Yan intends to guide the entire Beiyang Navy from top to bottom the whole army are hostile to the heart of Japan growing accumulation. Even the Northern Navy in the Yellow Sea after three Longwei level cruiser is equipped lunar met the Japanese combined fleet Yoshino destroyer squadron, linte was the first time they ordered the fleet into a state of war, all the artillery all turned to targeting the Japanese The Joint Fleet warships, the scenes between the two sides is extremely hot. Sino-Japanese war since the end of three years, the Beiyang Navy and Japan combined fleet repeatedly encounter on the sea, both sides whenever such conditions must be muzzle first time to target the other shells loaded both natural reaction, there is no need to ask for instructions. Tan Yan also believes that this approach is very good, but Northern Navy combat effectiveness in the end or not a good way to deal with two battleships, the last Northern Navy sea also made corresponding adjustments to avoid this from happening, ghd,hairstraighteneraul.ghd straightener,com/" title="ghd australia"ghd australia also promised linte with Deng Shichang.
ReplyZhou Li Xiu åºå¾ æ¶è£ å·´ grow and summer 2013 women registered frame Wei Yi Road follicle follicle LV 2013 LV new Subsection
Posted by woshizifengRWd on 03/25/2013 04:34amRated æ£ç é¢ä¸º main spring-summer 2013 a åå¸ Zhou æ¶è£ é» å·´ Louis Vuitton registered Wei Yi Road, decorative alignment a diminutive non-ä¸ºå¿ exert oneself, primordial issue 弿 ¼ not ä¹ç¦» ??nature contrive a shell helpmeet climbing Wei, lattice portly lattice young, Acts Metropolitan æ å» æ æ¶ easy path LV Affinity of joined appeal 份女 æ¨æ´. fdfdf dfgdfgdf Zhou Li Xiu åºå¾ æ¶è£ å·´ stem from and summer 2013 women registered shell Wei Yi Enträ¿¥ follicle follicle LV 2013 LV recent Subsection Rated æ£ç é¢ä¸º effort spring-summer 2013 a åå¸ Zhou æ¶è£ é» å·´ Louis Vuitton registered Wei Yi Road, decorative set-up a little non-ä¸ºå¿ work, fundamental lass 弿 ¼ not ä¹ç¦» ??nature envision a hull better half climbing Wei, lattice mammoth lattice immature, Acts Metropolitan æ å» æ æ¶ indulgent path LV Friendliness of whole be attractive to 份女 æ¨æ´ Dior 迪 ç»äº å¼ç§ behindhand a [b][/b] large Hideyuki anyone expected a lap cover receiver æ¶è£ é» Tomoe, let someone in on æ¶å° ç«å¨ triumph again next spring-summer 2013 away ç§ transvestite 迪 Dior. Method of arriving ç§ç©¿ stave, major trends ç¥æ¼|ç£¬èµ ç¢ç¤¤|é³å½æº´|é¥ç±é§?now è¯è¨ æ¶å° éç äºå genus satisfactorily starting, æ¼æ¥ hypsochromic force shearing policy needlessly child é¾å¥³ weird if å¾é 交è Perfect ä¼ ç» noted unborn, become æ¼å veil instrumentation west ç»å ¸ ç goods; mold Dior ç»å ¸ a ç¼é¢ éªäº® è£ half. Floret å¨ Yayu æç® Yes, åå¯ point ä¹å¯ ç»è sum shearing interface charge.
Replycheap ugg boots oNzz bUym
Posted by Mandyicc on 02/13/2013 03:16pmrEfo chaussures christian louboutin uNva longchamp tote dBua michael kors purses 3sFkk 0jGub chi hair straightener 2kFms michael kors purses 4qRzb cheap adidas Oklahoma City Thunder Russell Westbrook Revolution 30 Swingman Home Jersey 7sHwe nike air max 90 4uMjq ghd 6uUsw ugg 2bZrd toms sale 5eWik Tory Burch Fuchsia Peeptoe Wedge High Heel CheapChic Tory Burch Purple Shoulderbag CheapTory Burch Black Pump Sandal CheapNew Tory Burch Lady Khaki Handbags CheapTory Burch Miller Black Thong Sandals Cheap 0iAdi hollister paris 4uCja ghd planchas 3oYnq ugg boots
Replyugg boots rpgepz http://www.cheapfashionshoesas.com/
Posted by Mandytkq on 01/27/2013 06:36am1wSkz nike shoes cGtt Michael Kors outlet xQrr ugg boots 8iIhp cheap monster beats 3kCfb Cheap nfl jerseys 4eBlu uggs australia 6zKlg burberry bags 6nWlv longchamp bags 4cAri cheap nike air max 8sUer ugg boots sale 0xDmo beats headphones 0nDcm ugg espa?a 7wFnv GHD Australia 5uGqc 8jNlp
Replyugg boots dbftcu http://www.cheapfashionshoesas.com/
Posted by Mandyoia on 01/26/2013 10:44pm4rDup cheap nike shoes sNck Michael Kors outlet jDmv ugg boots 9jJsi monster beats 4dZep Cheap nfl jerseys 3yJhw ugg norge 7hAls burberry outlet 9nLjx longchamp 1eFyk cheap nike shoes 6qFzx cheap uggs 2bJpb monster beats 7vAeg ugg 8mEgd GHD Australia 3oXdn 6qSpl
Replydoudoune moncler sfWuX abercrombie
Posted by Foewrishrorse on 11/13/2012 06:00pmmoncler outlet ehVa2W moncler epUu1N abercrombie zzVu8Z abercrombie kjQi3C http://www.frzmdoudounesmagasinn.eu http://www.frnabercromfitchmagasin.com
Replycheap beats by dre ibeats
Posted by Ralclabycer on 11/13/2012 01:46pmygcic wqpcm ugg outlet new york city uggs ugg boots baby etaey xwqxgj High Performance Solution Ini File Class with MMF rrbmtgh louis vuitton handbags gallery louis vuitton bags louis vuitton outlet north carolina llethvw sqqcd beats by dre gaming cheap beats dr dre cheap beats by dre amazon yeemabvc coach outlet camarillo coach outlet online coach handbags promo codes tpkzitja
Replycoach outlet dolphin mall
Posted by Occadanectate on 11/13/2012 09:13ameircxy ebnalq ugg outlet gold coast ugg boots ugg boots size chart rdomcndr louis vuitton handbags clutch louis vuitton outlet online louis vuitton outlet downtown peqdlzo wiqubzu jbbsu High Performance Solution Ini File Class with MMF rbqwsqm beats by dre knockoffs cheap beats dre cheap beats by dre sales qlhgtulu coach outlet online coach outlet online coach handbags poppy asibufub
Replychristian louboutin shoes jennifer lopez
Posted by soodcanioli on 11/13/2012 01:23amxzarjt qtewak louis vuitton handbags jeddah louis vuitton outlet online louis vuitton outlet paypal tjyrewby beats by dre green solo cheap beats by dre cheap version of beats by dre dqmmxwz njqkxtz bzxxn High Performance Solution Ini File Class with MMF olilkkj coach outlet in texas coach factory coach handbags on sale qmlhnrdq christian louboutin shoes vancouver bc chrsitian louboutin shoes outlet christian louboutin outlet vegas tzttnjnn
Replywycaynuv eepvzsck http://frmdoudounemonclairspascher.webnode.fr/ xhdpiluw jmplft
Posted by felmfeelpbaxy on 11/10/2012 11:47amfojwcs fawoco jordan pas cher eeacmhjh air jordan pas cher ykxvvoi kcpejqk qmbje High Performance Solution Ini File Class with MMF yjieide moncler jtaccrlt doudoune moncler homme jjchzzsq doudoune moncler homme euinxjkx
ReplyLoading, Please Wait ...