1

My program manipulates an ini file using TIniFile. I've read TIniFile class has 64kb limit in single section. However, it seems to be working for more than 100kb in my tests. I'm using Delphi 10.3.3 and Windows 10.

Does 64kb limit exist only in old versions of Windows? Or, should I use TMemIniFile to stay safe?

Xel Naga
  • 826
  • 11
  • 28
  • 6
    Always use `TMemIniFile`. – Andreas Rejbrand Jan 22 '21 at 20:03
  • 1
    `TIniFile` itself does not impose any size limits. It is just a wrapper for the PrivateProfile API, so any limits will be in the OS itself. And [according to Raymond Chen](https://devblogs.microsoft.com/oldnewthing/20071126-00/?p=24383): "*INI files are limited to 32KB in size*", but that was 13 years ago. Maybe it has been upped since then. – Remy Lebeau Jan 22 '21 at 21:57
  • There seems to be no specific limit to the file size or text retreival size of the winapi function GetPrivateProfileString (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprivateprofilestring) as long as the buffer is big enough. However I do know (maybe in the old days) there was a limit on the buffer allocate inside TIniFile which was used with GetPrivateProfileString... But as this function isn’t very fast (but does perform good enough on smaller files), extensive use on large files is not adviced. – R. Hoek Jan 22 '21 at 22:31

1 Answers1

2

Basically, there is no limit to the size of an ini file or the routine GetPrivateProfileString (which is used by TIniFile to read the data). But there are some limits and things to consider when using TIniFile.

Looking into the code of the TIniFile implementation (thank you Delphi), there are several places where GetPrivateProfileString is used to retrieve data from an ini file.

In TIniFile.ReadString the buffer size is fixed to 2048 (2k) for reading string values. As all other 'value' requesting routines use this routine to actually read the data from the inifile, it basically limits the buffer size for all those routines.

Second, the TIniFile.ReadSections routine uses a starting buffer of 16384 (16k) characters. But when this buffer is too small it uses a dynamic buffer which is based on the file size, so this way you won't run into a buffer problem (but because this actually reads the entire file to estimate the buffer size, this will be very slow with large ini files).

Last, the TIniFile.ReadSection routine, which uses an initial buffer size of 1024 (1k). But dynamically allocates a larger buffer when needed. So at this point, there also doesn't seem to be a limit to the (file)size.

NOTE: this information is based on Delhi 10.3 and Delphi XE2. In older versions there we're other buffer allocation strategies...

R. Hoek
  • 916
  • 8
  • 27