INI Library - FAST in memory functions NO REGEX
Posted 24 January 2011 - 04:50 PM
If you've seen me around you might already know: I try to make every bit of code I write as fast as possible.
I was recently trying to help someone speed up there ini code (using a different ini library someone else posted) but the way the library was setup it was not possible. That led to the idea for this library.
Current version: 1.5
Download: FAST INI library Advanced
Download: FAST INI library Basic
Basic is all of the "HE" functions (with "HE" removed) and none of the low/no E functions. Other then that, there is no difference.
Basic + AHK_L ANSI and Unicode compatible (x86/x64) - supports unicode sections/keys/values
Standard Library compliant - and not "ini.ahk" so it wont clash with other ini libs
ANY comments/suggestions about anything - feel free to post!
In addition to all the standard features you would expect with an ini library the following contains a partial list of the extra things I’ve added.
Features of this library:
> Append to key values (add to the end of)
> Auto key a delimiter split variable with the key prefix you choose
> Copy keys (and values/comments) from one section to another and optionally from one ini to another
> Copy sections from one ini to another but none of the keys
> Copy a section (and its keys/values) from one section to another and optionally from one ini to another
> Clone a key (and its value/comment) to a different key and optionally to another section optionally to another ini
> Rename section(s)/key(s)
> Sort sections/keys A-Z, Z-A, 0-9, 9-0 or any other way you can sort with the AHK "Sort" command
> Swap 2 sections contents
> Get a (CSV or user defined split) list of all sections
> Get a (CSV or user defined split) list of all keys within a section
> Get all values of keys with a specific name
> Get the total size of a stored ini
> Get the total size of a section (and its associated keys/values/comments)
> Get the total size of a key (and its associated values/comments)
> Count the number of sections
> Count the total number of keys or keys in a section
> Delete a section (and its associated keys/values/comments)
> Delete a key (and its associated value/comment)
> Convert ini to variable/variable to ini
> Merge INIs with options to replace/append/ignore duplicate sections plus separate options to replace/append/ignore duplicate keys and options to remove blank sections/keys
> SUPER fast all in-memory functions (altering a section/keys doesn't slow down other sections/keys)
> Supports in-line section and key comments as well as normal comments
> Supports sections/keys with spaces in the names (High_E and some Low_E only)
> Multiple functions with varying levels of error checking for when you know your input won’t cause problems - less error checking means faster execution.
> Optionaly trim spaces from key values and or `r/`n characters from key values
> Add sections as keys to a section
> Add keys as sections to a ini
> Delete all keys from a section
> Delete key values from a section and or delete key comments from a section
> Find what section a key is in
> Check if a section/Key exists
NOTE: Section and Key names are limited to letters, numbers and the following punctuation: # _ @ $ and space
Reference_Number + Section names cannot exceed 233 characters total.
Reference_Number + Section + Key names cannot exceed 243 characters total
Key values can contain any length values and are limited only by how large the #MaxMem amount is and how much RAM the build of AHK you are using can use.
Basic documentation/help (incomplete - i'm lazy and nobody has asked for it yet):
> HTML version
If you have a specific function you would like explained please ask. It would probably drive me to write up a good example/how-to for that function.
Current list of functions:
Example 1 - read and access a ini:
Read and access a ini
Example 2 - merge 2 inis:
Merge 2 inis
Example 3 - create an ini from scratch using no_e functions:
Create an ini from scratch using No_E functions
All of the functions are fast, but! For the person who REALLY wants speed I made most functions have multiple versions. Even the "slowest" of them should still be way faster than any other ini functions you might find elsewhere.
Advanced version only:
"HE" means high error checking - slowest of the options but safest
"LE" means low error checking - medium speed
"NE" means no error checking - fastest but requires you only pass them valid input in the correct order. No_E functions require sections/keys passed to them to have no spaces in them.
If you aren’t sure which one to use go with "HE" as it will work 99% of the time. (I don't want to say 100% because nothing is perfect )
Depending on what you’re doing with your ini this could be up to 500 times faster than the built in AHK ini functions or other libraries. The more complex things you want to do with the ini the faster this library should be in comparison to anything else.
My speed test: Add a random 18 character value to a key 926513 times in a row. Computer: Acer netbook
Time to add all 926513 18 character values 1 at a time to a single key: 6.6 seconds
As always, if you find any bugs or have any problems let me know and I will fix them.
How it works:
1 variable holds a sections name
1 variable holds the “top” comments – comments before any section
1 variable holds a sections comment
1 variable holds a sections “lone line” comments – comments on their own line
1 variable holds a sections keys
1 variable holds a keys value
1 variable holds a keys comment
The sections variable points to a section and its comment(s) -> the section points to the keys -> the keys point to the values and keys comments
Having it setup this way prevents slowdowns from a traditional single variable ini. The larger a single variable ini gets the slower functions are to operate on it. Because my functions are operating on different variables for each section/key/comment having large amounts of data in one section/key doesn’t slow down operation on other sections/keys.
Posted 26 January 2011 - 10:18 PM
> Added support for comments; inline section comments, inline key comments and normal whole-line comments
> Added support for "[Sections]" and "Keys=" with spaces in them
> Changed the functions from "No_E" and "With_E" to now be "High_E" "Low_E" and "No_E"
> Other stuff I probably forgot
Posted 27 January 2011 - 03:43 AM
> Started limited documentation
> Added a function to get the ini size stored in RAM
Posted 27 January 2011 - 03:47 AM
Posted 27 January 2011 - 03:54 AM
but why not separate the high_e, low_e and no_e versions into separate files, so that somebody who wants only the high_e version does not have to mention _high_e for every function?
Posted 27 January 2011 - 03:59 AM
If one really wanted to they could rename functions/delete ones they don't want.
Also: Can either of you think of any other functions that anyone might find useful? I still have a few things to change but the current functions fully work.
Posted 27 January 2011 - 04:15 AM
there are atleast 7 global variables, some with variable name as common as position, which may conflict with users variables.
another small thing,
Ini_Unicode_Modifier := A_IsUnicode = 1 ? 2 : 1can be represented as
Ini_Unicode_Modifier := A_IsUnicode ? 2 : 1
please take all this as constructive criticism
Posted 27 January 2011 - 04:20 AM
Would you happen to know what the variables might be? I thought I made all of the basic variables local.
Edit: Fixed the Position one.
Posted 27 January 2011 - 04:53 AM
Posted 27 January 2011 - 05:42 AM
I THINK I fixed all the global variables. Listvars showed only Ini_Unicode_Modifier. I updated the download link with the fixed version: 0.4.1
Any suggestions on functions to add or other problems you've found?
Posted 28 January 2011 - 12:01 AM
> Added support for handling multiple sections/keys when you read a ini file. (remove, append, replace, add new keys only)
> Fixed some problems with the expand and contract functions.
> Added functions to get the total size of a section or key.
> Added checking in the High_E functions to reduce the amount of memory used.
> Changed the checking in the High_E functions to execute faster(more speed).
> Changed some variable names to prevent possible conflicts.
Posted 02 February 2011 - 04:48 AM
> Reordered the code to increase the speed of the High_E functions
> Added "Read blank sections" and "Read blank keys" options to the Ini_Read_High_E function
> Added "Write blank sections" and "Write blank keys" options to the Ini_Write_High_E function
> Added "Add blank sections" and "Add blank keys" options to the Ini_To_Variable_High_E function
> Added "Merge blank sections" and "Merge blank keys" options to the Ini_Merge_High_E function
> Fixed a bug with the Ini_Merge_High_E function where it would skip merging lone-line comments from the source ini
> Fixed a bug with the Ini_To_Variable_High_E function where it would give values to keys that didn't have one
> Added Ini_Variable_To_Ini functions (oposite of ini to variable)
> Cleaned up some of the code in the read/write/to/from variable functions
If anyone has any ideas for functions feel free to post! I ran out of ideas myself.
Posted 03 February 2011 - 07:47 AM
> Added copy section names high/low E functions - copy sections to another ini without any of the key values
> Added copy section high/low E functions - copy a section and all of its keys from one section to another optionally from one ini to another
> Added clone key high/low E functions - clone a key and it's value/comment to another key optionally another section optionally another ini
> Added rename section/key high/low E functions
> Added sort sections/keys high/low E functions - sort sections/keys any way you can sort with the autohotkey "sort" command
> Changed the copy keys function so it optionally lets you copy keys from one section to another optionally one ini to another
> Changed the ini write high E function so it has a optional paramater of spacing sections and or keys apart with a newline
> Changed the ini to variable high E function so it has a optional paramter of spacing sections and or keys apart with a newline
> Changed the ini read high E function so it supports comments that are indented with tabs or spaces
> Fixed a bug with the ini merge high E and and the ini read high E functions where they would miss seeing duplicate sections if the section it was looking for was the first in the list of sections
> Fixed a bug with the Ini_Write functions where they would return errors if you did not have a ini setup with the reference number of 1
Posted 06 February 2011 - 09:44 PM
> Further increased the speed of the High E functions
> Fixed a bug with some functions returning the wrong error messages ("? already exists" when it should return "? doesn't exist")
> Fixed a bug with the ini merge High E function where it would add section comments twice
> Fixed a bug with the ini write functions where it wouldn't write if the total size of the ini was above the #MaxMem amount
Posted 09 February 2011 - 01:55 AM
> Added add_sections_as_keys high/low error checking functions - adds all of the sections (optionaly skipping the section it's going to) as keys to a section
> Added add_keys_as_sections high/low error checking functions - add all of the keys from a section as sections to the ini (optionaly skipping the section they are coming from)
> Added alter_section_keys high/low error checking functions - delete all the keys in a section, or delete all the values of keys in a section and or delete all the comments of keys in a section
> Altered the Ini_Read high/low error checking functions to return different error levels if there is any problem saving the file
> Altered the Read_High_E function to have a trim spaces from values optional paramater
> Altered the Ini_Read high/low error checking functions to skip broken lines if correct_errors is set to 1 and to return a csv numbered list of the broken lines
> Altered the append_value_high_e, set_key_value_high_e, to_variable_high_e and ini_write_high_e functions to have optional paramaters to remove newline (`r/`n) characters from key values
> Altered the Get_Sections and Get_Section_Keys high/low error checking functions to have a optional delimiter option (default is comma)
> Cleaned up the code in the Ini_Read high/low error checking functions and Variable_To_INI_High_E that deals with skipping key comments if the optional paramater is enabled
> Fixed a bug with the ini_write functions where it would not write unicode characters
> Fixed a bug with all of the functions that had a "Something_Blank_Keys" option where it would count 0 as blank when it should only count "" as blank