Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

INI Library - FAST in memory functions NO REGEX


  • Please log in to reply
48 replies to this topic
Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Hello all,

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.7

Download: FAST INI library
 

Old versions:

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
Multiple functions with varying levels of error checking for when you know your input won’t cause problems - less error checking means faster execution.
> Optionally 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
 

EDIT: none of this applies in the 1.6 and later versions
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:
Standard + Basic list
Advanced list

 

Examples

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


Information (1.5 only):
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 (1.5 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.



Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.3:
> 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

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.4:
> Started limited documentation
> Added a function to get the ini size stored in RAM

codybear
  • Members
  • 600 posts
  • Last active: Feb 09 2015 12:41 PM
  • Joined: 15 Sep 2009
looks very promising. Keep it up! When I boot into windows tomorrow I'll have to check this out!

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
wonderful work! pls develop it further.

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?
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
I thought about putting them in different files but opted not to because I thought it would add a lot of maintenance time if I ever changed parts of one function I would have to go across 3 different files and such.

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? :D I still have a few things to change but the current functions fully work.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
also, a couple more things..

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 : 1
can be represented as
Ini_Unicode_Modifier := A_IsUnicode ? 2 : 1

please take all this as constructive criticism :)
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Thanks, I switched the unicode around.

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.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
just open scite4autohotkey, debug your script and check the variables list..

Posted Image
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Thanks :) I should have checked that a long time ago.

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?

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.5:
> 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.

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.6:
> 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.

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.7:
> 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

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.8:
> 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

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010
Updated to 0.9:
> 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