logo.png
mORMot2 API Reference

mormot.core.base.pas unit

Purpose: Framework Core Shared Types and RTL-like Functions
- this unit is a part of the Open Source Synopse mORMot framework 2, licensed under a MPL/GPL/LGPL three license - see LICENSE.md

1.1. mormot.core.base class hierarchy

TStreamWithPositionTStreamWithPositionAndSizeTRawByteStringStreamTStreamTObjectTSynTempBufferTSortedWordArrayTSortedIntegerArrayTLecuyerTCustomMemoryStreamTSynMemoryStreamExceptionExceptionWithProps
mormot.core.base class hierarchy

1.2. Objects implemented in the mormot.core.base unit

ObjectsDescription
TDiv100RecSmall structure used as convenient result to Div100() procedure
TDWordRecBinary access to an unsigned 32-bit value (4 bytes in memory)
TDynArrayRec32-bit longint with Delphi map the Delphi/FPC dynamic array header (stored before each instance)
THash128RecMap a 128-bit hash as an array of lower bit size values
THash256RecMap a 256-bit hash as an array of lower bit size values
THash512RecMap a 512-bit hash as an array of lower bit size values
TIntelAvx10FeaturesThe AVX10 Converged Vector ISA features
TLecuyer32-bit Pierre L'Ecuyer software (random) generator
TQWordRecBinary access to an unsigned 64-bit value (8 bytes in memory)
TRawByteStringStreamTStream using a RawByteString as internal storage
TSortedIntegerArrayUsed to store and retrieve Integers in a sorted array
TSortedWordArrayUsed to store and retrieve Words in a sorted array
TStreamWithPositionTStream with a protected fPosition field
TStreamWithPositionAndSizeTStream with two protected fPosition/fSize fields
TStrRecMap the Delphi/FPC string header (stored before each instance)
TSynMemoryStreamTStream pointing to some existing in-memory data, for instance UTF-8 text
TSynTempBufferImplements a 4KB stack-based storage of some (UTF-8 or binary) content
TSynVarDataA variant/TVarData overlapped structure with a 32-bit VType field

1.2.1. TStrRec

TStrRec = packed record

Map the Delphi/FPC string header (stored before each instance)


length: TStrLen;

32-bit longint with Delphi equals length(s) - i.e. size in AnsiChar/WideChar, not bytes


refCnt: TStrCnt;

String reference count (basic garbage memory mechanism)


1.2.2. TDynArrayRec

TDynArrayRec = packed record

32-bit longint with Delphi map the Delphi/FPC dynamic array header (stored before each instance)


length: TDALen;

32-bit longint with Delphi length in element count
- size in bytes = length*ElemSize


refCnt: TDACnt;

Dynamic array reference count (basic garbage memory mechanism)


1.2.3. TDiv100Rec

TDiv100Rec = packed record

Small structure used as convenient result to Div100() procedure


D: cardinal;

Contains V div 100 after Div100(V)


M: cardinal;

Contains V mod 100 after Div100(V)


1.2.4. TSortedWordArray

TSortedWordArray = object(TObject)

Used to store and retrieve Words in a sorted array
- ensure Count=0 before use - if not defined as a private member of a class


Count: PtrInt;

How many items are currently in Values[]


Values: TWordDynArray;

The actual 16-bit word storage


function Add(aValue: Word): PtrInt;

Add a value into the sorted array
- return the index of the new inserted value into the Values[] array
- return -(foundindex+1) if this value is already in the Values[] array


function IndexOf(aValue: Word): PtrInt;

Return the index if the supplied value in the Values[] array
- return -1 if not found


procedure SetArray(out aValues: TWordDynArray);

Save the internal array into a TWordDynArray variable


1.2.5. TSortedIntegerArray

TSortedIntegerArray = object(TObject)

Used to store and retrieve Integers in a sorted array
- ensure Count=0 before use - if not defined as a private member of a class


Count: PtrInt;

How many items are currently in Values[]


Values: TIntegerDynArray;

The actual 32-bit integers storage


function Add(aValue: integer): PtrInt;

Add a value into the sorted array
- return the index of the new inserted value into the Values[] array
- return -(foundindex+1) if this value is already in the Values[] array


function IndexOf(aValue: integer): PtrInt;

Return the index if the supplied value in the Values[] array
- return -1 if not found


procedure SetArray(out aValues: TIntegerDynArray);

Save the internal array into a TWordDynArray variable


1.2.6. TDWordRec

TDWordRec = record

Binary access to an unsigned 32-bit value (4 bytes in memory)


1.2.7. TQWordRec

TQWordRec = record

Binary access to an unsigned 64-bit value (8 bytes in memory)


1.2.8. THash128Rec

THash128Rec = packed record

Map a 128-bit hash as an array of lower bit size values
- consumes 16 bytes of memory


1.2.9. THash256Rec

THash256Rec = packed record

Map a 256-bit hash as an array of lower bit size values
- consumes 32 bytes of memory


1.2.10. THash512Rec

THash512Rec = packed record

Map a 512-bit hash as an array of lower bit size values
- consumes 64 bytes of memory


1.2.11. TIntelAvx10Features

TIntelAvx10Features = record

The AVX10 Converged Vector ISA features


MaxSubLeaf: cardinal;

Maximum supported sub-leaf


Vector: TIntelAvx10Vector;

Bit vector size support


Version: byte;

The ISA version (>= 1)


1.2.12. TLecuyer

TLecuyer = object(TObject)

32-bit Pierre L'Ecuyer software (random) generator
- cross-compiler and cross-platform efficient randomness generator, very fast with a much better distribution than Delphi system's Random() function see https://www.gnu.org/software/gsl/doc/html/rng.html#c.gsl_rng_taus2
- used by thread-safe Random32/RandomBytes, storing 16 bytes per thread - a stronger algorithm like Mersenne Twister (as used by FPC RTL) requires 5KB
- SeedGenerator() makes it a sequence generator - or encryptor via Fill()
- when used as random generator (default when initialized with 0), Seed() will gather and hash some system entropy to initialize the internal state


function Next: cardinal; overload;

Compute the next 32-bit generated value
- will automatically reseed after around 2^32 generated values, which is huge but very conservative since this generator has a period of 2^88


function Next(max: cardinal): cardinal; overload;

Compute the next 32-bit generated value, in range [0..max-1]


function NextDouble: double;

Compute a 64-bit floating point value


function NextQWord: QWord;

Compute a 64-bit integer value


function RawNext: cardinal;

Compute the next 32-bit generated value with no Seed - internal call


procedure Fill(dest: pointer; bytes: integer);

XOR some memory buffer with random bytes
- when used as sequence generator after SeedGenerator(), dest buffer should be filled with zeros before the call if you want to use it as generator, but could be applied on any memory buffer for encryption


procedure FillShort(var dest: ShortString; size: PtrUInt = 255);

Fill some string[0..size] with 7-bit ASCII random text


procedure FillShort31(var dest: TShort31);

Fill some string[0..31] with 7-bit ASCII random text


procedure Seed(entropy: PByteArray = nil; entropylen: PtrInt = 0);

Force a random seed of the generator from current system state
- as executed by the Next method at thread startup, and after 2^32 values
- calls XorEntropy(), so RdRand32/Rdtsc opcodes on Intel/AMD CPUs


procedure SeedGenerator(fixedseed: QWord); overload;

Force a well-defined seed of the generator from a fixed initial point
- to be called before Next/Fill to generate the very same output
- will generate up to 16GB of predictable output, then switch to random


procedure SeedGenerator(fixedseed: pointer; fixedseedbytes: integer); overload;

Force a well-defined seed of the generator from a buffer initial point
- apply crc32c() over the fixedseed buffer to initialize the generator


1.2.13. TSynTempBuffer

TSynTempBuffer = object(TObject)

Implements a 4KB stack-based storage of some (UTF-8 or binary) content
- could be used e.g. to make a temporary copy when JSON is parsed in-place
- call one of the Init() overloaded methods, then Done to release its memory
- will avoid temporary memory allocation via the heap for up to 4KB of data
- all Init() methods will allocate 16 more bytes, for a trailing #0 and to ensure our fast JSON parsing won't trigger any GPF (since it may read up to 4 bytes ahead via its PInteger() trick) or any SSE4.2 function


buf: pointer;

Where the text/binary is available (and any Source has been copied)
- equals nil if len=0


len: PtrInt;

The text/binary length, in bytes, excluding the trailing #0


tmp: array[0..4095] of AnsiChar;

Default 4KB buffer allocated on stack - after the len/buf main fields
- 16 last bytes are reserved to prevent potential buffer overflow, so usable length is 4080 bytes


function BufEnd: pointer;

Inlined wrapper around buf + len


function Init(SourceLen: PtrInt): pointer; overload;

Initialize a new temporary buffer of a given number of bytes
- also include ending #0 at SourceLen position


function Init: integer; overload;

Initialize the buffer returning the internal buffer size (4080 bytes)
- also set len to the internal buffer size
- could be used e.g. for an API call, first trying with plain temp.Init and using temp.buf and temp.len safely in the call, only calling temp.Init(expectedsize) if the API returns an insufficient buffer error


function Init(Source: PUtf8Char): PUtf8Char; overload;

Initialize a temporary copy of the supplied text buffer, ending with #0


function InitIncreasing(Count: PtrInt; Start: PtrInt = 0): PIntegerArray;

Initialize a new temporary buffer filled with 32-bit integer increasing values


function InitOnStack: pointer;

Initialize a temporary buffer with the length of the internal stack


function InitRandom(RandomLen: integer): pointer;

Initialize a new temporary buffer of a given number of random bytes
- will fill the buffer via RandomBytes() call


function InitZero(ZeroLen: PtrInt): pointer;

Initialize a new temporary buffer of a given number of zero bytes
- if ZeroLen=0, will initialize the whole tmp[] stack buffer to 0


procedure Done; overload;

Finalize the temporary storage


procedure Done(EndBuf: pointer; var Dest: RawUtf8); overload;

Finalize the temporary storage, and create a RawUtf8 string from it


procedure Init(Source: pointer; SourceLen: PtrInt); overload;

Initialize a temporary copy of the supplied text buffer
- also include ending #0 at SourceLen position


procedure Init(const Source: RawByteString); overload;

Initialize a temporary copy of the content supplied as RawByteString
- will also allocate and copy the ending #0 (even for binary)


1.2.14. TSynVarData

TSynVarData = packed record

A variant/TVarData overlapped structure with a 32-bit VType field
- 32-bit VType is faster for initialization than 16-bit TVarData.VType
- it is safe to transtype this as plain variant or TVarData


VInteger: integer

Access the most used TVarData value members


1.2.15. TStreamWithPosition

TStreamWithPosition = class(TStream)

TStream with a protected fPosition field


function Seek(Offset: Longint; Origin: Word): Longint; override;

Call the 64-bit Seek() overload


function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;

Change the current Read/Write position, within current GetSize


1.2.16. TStreamWithPositionAndSize

TStreamWithPositionAndSize = class(TStreamWithPosition)

TStream with two protected fPosition/fSize fields


1.2.17. TRawByteStringStream

TRawByteStringStream = class(TStreamWithPosition)

TStream using a RawByteString as internal storage
- default TStringStream uses UTF-16 WideChars since Delphi 2009, so it is not compatible with previous versions or FPC, and it makes more sense to work with RawByteString/RawUtf8 in our UTF-8 oriented framework
- just like TStringStream, is designed for appending data, not modifying in-place, as requested e.g. by TJsonWriter or TBufferWriter classes


constructor Create(const aString: RawByteString); overload;

Initialize the storage, optionally with some RawByteString content
- to be used for Read() from this memory buffer


function Read(var Buffer; Count: Longint): Longint; override;

Read some bytes from the internal storage
- returns the number of bytes filled into Buffer (<=Count)


function Write(const Buffer; Count: Longint): Longint; override;

Append some data to the buffer
- will resize the buffer, i.e. will replace the end of the string from the current position with the supplied data


procedure Clear;

Reset the internal DataString content and the current position


procedure GetAsText(StartPos, Len: PtrInt; var Text: RawUtf8);

Retrieve the stored content from a given position, as UTF-8 text
- warning: may directly return DataString and reset its value to ''


property DataString: RawByteString read fDataString write fDataString;

Direct low-level access to the internal RawByteString storage


1.2.18. TSynMemoryStream

TSynMemoryStream = class(TCustomMemoryStream)

TStream pointing to some existing in-memory data, for instance UTF-8 text
- warning: there is no local copy of the supplied content: the source data must be available during all the TSynMemoryStream usage


constructor Create(Data: pointer; DataLen: PtrInt); overload;

Create a TStream with the supplied data buffer
- warning: there is no local copy of the supplied content: the Data/DataLen buffer must be available during all the TSynMemoryStream usage: don't release the source Data before calling TSynMemoryStream.Free


constructor Create(const aText: RawByteString); overload;

Create a TStream with the supplied text data
- warning: there is no local copy of the supplied content: the aText variable must be available during all the TSynMemoryStream usage: don't release aText before calling TSynMemoryStream.Free
- aText can be on any AnsiString format, e.g. RawUtf8 or RawByteString


function Write(const Buffer; Count: Longint): Longint; override;

This TStream is read-only: calling this method will raise an exception


1.3. Types implemented in the mormot.core.base unit

1.3.1. HalfInt

HalfInt = smallint;

A CPU-dependent signed integer type cast of half a pointer


1.3.2. HalfUInt

HalfUInt = word;

A CPU-dependent unsigned integer type cast of half a pointer


1.3.3. PBlock128

PBlock128 = ^TBlock128;

Pointer to a 128-bit buffer


1.3.4. PBooleanArray

PBooleanArray = ^TBooleanArray;

Redefine here with {$R-}


1.3.5. PDACnt

PDACnt = ^TDACnt;

Pointer to cross-compiler type used for dynarray reference counter


1.3.6. PDALen

PDALen = ^TDALen;

Pointer to cross-compiler type used for dynamic array length


1.3.7. PDateTimeMSDynArray

PDateTimeMSDynArray = ^TDateTimeMSDynArray;

Pointer to a dynamic array of TDateTimeMS values


1.3.8. PDWordRec

PDWordRec = ^TDWordRec;

Points to the binary of an unsigned 32-bit value


1.3.9. PHalfInt

PHalfInt = ^HalfInt;

A CPU-dependent signed integer type cast of a pointer to half a pointer


1.3.10. PHalfUInt

PHalfUInt = ^HalfUInt;

A CPU-dependent unsigned integer type cast of a pointer to half a pointer


1.3.11. PHash128

PHash128 = ^THash128;

Pointer to a 128-bit hash value


1.3.12. PHash128Array

PHash128Array = ^THash128Array;

Pointer to an infinite array of 128-bit hash values


1.3.13. PHash128Rec

PHash128Rec = ^THash128Rec;

Pointer to 128-bit hash map variable record


1.3.14. PHash160

PHash160 = ^THash160;

Pointer to a 160-bit hash value


1.3.15. PHash192

PHash192 = ^THash192;

Pointer to a 192-bit hash value


1.3.16. PHash224

PHash224 = ^THash224;

Pointer to a 224-bit hash value


1.3.17. PHash256

PHash256 = ^THash256;

Pointer to a 256-bit hash value


1.3.18. PHash256Array

PHash256Array = ^THash256Array;

Pointer to an infinite array of 256-bit hash values


1.3.19. PHash256Rec

PHash256Rec = ^THash256Rec;

Pointer to 256-bit hash map variable record


1.3.20. PHash384

PHash384 = ^THash384;

Pointer to a 384-bit hash value


1.3.21. PHash512

PHash512 = ^THash512;

Pointer to a 512-bit hash value


1.3.22. PHash512Array

PHash512Array = ^THash512Array;

Pointer to an infinite array of 512-bit hash values


1.3.23. PHash512Rec

PHash512Rec = ^THash512Rec;

Pointer to 512-bit hash map variable record


1.3.24. PID

PID = ^TID;

A pointer to TOrm.ID, i.e. our ORM primary key


1.3.25. PIDDynArray

PIDDynArray = ^TIDDynArray;

Pointer to a dynamic array of ORM primary keys, i.e. TOrm.ID


1.3.26. PMethod

PMethod = ^TMethod;

This pointer is not defined on older Delphi revisions


1.3.27. PPtrInt

PPtrInt = ^PtrInt;

A CPU-dependent signed integer type cast of a pointer of pointer
- used for 64-bit compatibility, native under Free Pascal Compiler


1.3.28. PPtrUInt

PPtrUInt = ^PtrUInt;

A CPU-dependent unsigned integer type cast of a pointer of pointer
- used for 64-bit compatibility, native under Free Pascal Compiler


1.3.29. PQWord

PQWord = ^QWord;

Points to an unsigned Int64


1.3.30. PQWordRec

PQWordRec = ^TQWordRec;

Points to the binary of an unsigned 64-bit value


1.3.31. PRawByteString

PRawByteString = ^RawByteString;

Pointer to a RawByteString


1.3.32. PSingle

PSingle = System.PSingle;

Redefined here to not use the unexpected PSingle definition from Windows unit


1.3.33. PStrCnt

PStrCnt = ^TStrCnt;

Pointer to cross-compiler type used for string reference counter


1.3.34. PStrLen

PStrLen = ^TStrLen;

Pointer to cross-compiler type used for string length


1.3.35. PStrRec

PStrRec = ^TStrRec;

PtrInt/NativeInt


1.3.36. PSynVarData

PSynVarData = ^TSynVarData;

Access to all standard value members


1.3.37. PtrInt

PtrInt = integer;

A CPU-dependent signed integer type cast of a pointer / register
- used for 64-bit compatibility, native under Free Pascal Compiler


1.3.38. PtrUInt

PtrUInt = cardinal;

A CPU-dependent unsigned integer type cast of a pointer / register
- used for 64-bit compatibility, native under Free Pascal Compiler


1.3.39. PUInt64

PUInt64 = ^UInt64;

Compatibility definition with FPC and newer Delphi


1.3.40. PUnixMSTime

PUnixMSTime = ^TUnixMSTime;

Pointer to a timestamp stored as millisecond-based Unix Time


1.3.41. PUnixTime

PUnixTime = ^TUnixTime;

Pointer to a timestamp stored as second-based Unix Time


1.3.42. PUtf8Char

PUtf8Char = type PAnsiChar;

A simple wrapper to UTF-8 encoded zero-terminated PAnsiChar
- PAnsiChar is used only for Win-Ansi encoded text
- the Synopse mORMot framework uses mostly this PUtf8Char type, because all data is internally stored and expected to be UTF-8 encoded


1.3.43. PWord

PWord = System.PWord;

Redefined here to not use the unexpected PWord definition from Windows unit


1.3.44. QWord

QWord = type Int64;

Unsigned Int64 doesn't exist under older Delphi, but is defined in FPC
- and UInt64 is buggy as hell under Delphi 2007 when inlining functions: older compilers will fallback to signed Int64 values
- anyway, consider using SortDynArrayQWord() to compare QWord values in a safe and efficient way, under a CPUX86
- use UInt64 explicitly in your computation (like in mormot.crypt.ecc), if you are sure that Delphi 6-2007 compiler handles your code as expected, but mORMot code will expect to use QWord for its internal process (e.g. ORM/SOA serialization)


1.3.45. RawBlob

RawBlob = type RawByteString;

A RawByteString sub-type used to store the BLOB content in our ORM
- equals RawByteString for byte storage
- TRttiInfo.AnsiStringCodePage will identify this type, and return CP_RAWBLOB fake codepage for such a published property, even if it is just an alias to CP_RAWBYTESTRING
- our ORM will therefore identify such properties as BLOB
- by default, the BLOB fields are not retrieved or updated with raw TRest.Retrieve() method, that is "Lazy loading" is enabled by default for blobs, unless TRestClientUri.ForceBlobTransfert property is TRUE (for all tables), or ForceBlobTransfertTable[] (for a particular table); so use RetrieveBlob() methods for handling BLOB fields
- could be defined as value in a TOrm property as such:

 property Blob: RawBlob read fBlob write fBlob;

- is defined here for proper TRttiProp.WriteAsJson serialization


1.3.46. RawByteString

RawByteString = type AnsiString;

Define RawByteString, as it does exist in Delphi 2009+
- to be used for byte storage into an AnsiString
- use this type if you don't want the Delphi compiler not to do any code page conversions when you assign a typed AnsiString to a RawByteString, i.e. a RawUtf8 or a WinAnsiString


1.3.47. RawJson

RawJson = type RawUtf8;

RawJson will indicate that this variable content would stay as raw JSON
- i.e. won't be serialized into values
- could be any JSON content: number, boolean, null, string, object or array
- e.g. interface-based service will use it for efficient and AJAX-ready transmission of TOrmTableJson result


1.3.48. RawUcs4

RawUcs4 = TIntegerDynArray;

Low-level storage of UCS4 CodePoints, stored as 32-bit integers


1.3.49. RawUnicode

RawUnicode = type AnsiString;

Low-level RawUnicode as an Unicode String stored in an AnsiString
- DEPRECATED TYPE, introduced in Delphi 7/2007 days: SynUnicode is to be used
- faster than WideString, which are allocated in Global heap (for COM)
- an AnsiChar(#0) is added at the end, for having a true WideChar(#0) at ending
- length(RawUnicode) returns memory bytes count: use (length(RawUnicode) shr 1) for WideChar count (that's why the definition of this type since Delphi 2009 is AnsiString(1200) and not UnicodeString)
- pointer(RawUnicode) is compatible with Win32 'Wide' API call
- mimic Delphi 2009 UnicodeString, without the WideString or Ansi conversion overhead
- all conversion to/from AnsiString or RawUtf8 must be explicit: the compiler may not be able to perform implicit conversions on CP_UTF16


1.3.50. RawUtf8

RawUtf8 = System.UTF8String;

RawUtf8 is an UTF-8 String stored in an AnsiString, alias to System.UTF8String
- all conversion to/from string or WinAnsiString must be explicit on Delphi 7/2007, and it will be faster anyway to use our optimized functions from mormot.core.unicode.pas unit like StringToUtf8/Utf8ToString


1.3.51. SpiUtf8

SpiUtf8 = type RawUtf8;

CP_UTF8 Codepage a RawUtf8 value which may contain Sensitive Personal Information (e.g. a bank card number or a plain password)
- identified as a specific type e.g. to be hidden in the logs - when the woHideSensitivePersonalInformation TTextWriterWriteObjectOption is set


1.3.52. SynUnicode

SynUnicode = WideString;

SynUnicode is the fastest available Unicode native string type, depending on the compiler used
- this type is native to the compiler, so you can use Length() Copy() and such functions with it (this is not possible with RawUnicodeString type)
- before Delphi 2009+, it uses slow OLE compatible WideString (with our Enhanced RTL, WideString allocation can be made faster by using an internal caching mechanism of allocation buffers - WideString allocation has been made much faster since Windows Vista/Seven)
- starting with Delphi 2009, it uses the faster UnicodeString type, which allow Copy On Write, Reference Counting and fast heap memory allocation
- on recent FPC, HASVARUSTRING is defined and native UnicodeString is set


1.3.53. TArm32HwCap

TArm32HwCap = ( arm32SWP, arm32HALF, arm32THUMB, arm3226BIT, arm32FAST_MULT, arm32FPA, arm32VFP, arm32EDSP, arm32JAVA, arm32IWMMXT, arm32CRUNCH, arm32THUMBEE, arm32NEON, arm32VFPv3, arm32VFPv3D16, arm32TLS, arm32VFPv4, arm32IDIVA, arm32IDIVT, arm32VFPD32, arm32LPAE, arm32EVTSTRM, arm32_22, arm32_23, arm32_24, arm32_25, arm32_26, arm32_27, arm32_28, arm32_29, arm32_30, arm32_31, arm32AES, arm32PMULL, arm32SHA1, arm32SHA2, arm32CRC32 );

32-bit ARM Hardware capabilities
- merging AT_HWCAP and AT_HWCAP2 flags as reported by github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/hwcap.h
- is defined on all platforms for cross-system use


1.3.54. TArm64HwCap

TArm64HwCap = ( arm64FP, arm64ASIMD, arm64EVTSTRM, arm64AES, arm64PMULL, arm64SHA1, arm64SHA2, arm64CRC32, arm64ATOMICS, arm64FPHP, arm64ASIMDHP, arm64CPUID, arm64ASIMDRDM, arm64JSCVT, arm64FCMA, arm64LRCPC, arm64DCPOP, arm64SHA3, arm64SM3, arm64SM4, arm64ASIMDDP, arm64SHA512, arm64SVE, arm64ASIMDFHM, arm64DIT, arm64USCAT, arm64ILRCPC, arm64FLAGM, arm64SSBS, arm64SB, arm64PACA, arm64PACG, arm64DCPODP, arm64SVE2, arm64SVEAES, arm64SVEPMULL, arm64SVEBITPERM, arm64SVESHA3, arm64SVESM4, arm64FLAGM2, arm64FRINT, arm64SVEI8MM, arm64SVEF32MM, arm64SVEF64MM, arm64SVEBF16, arm64I8MM, arm64BF16, arm64DGH, arm64RNG, arm64BTI, arm64MTE );

64-bit AARCH64 Hardware capabilities
- merging AT_HWCAP and AT_HWCAP2 flags as reported by github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/ahccap.h
- is defined on all platforms for cross-system use


1.3.55. TBits32

TBits32 = set of 0..31;

Fast access to 32-bit integer bits
- compiler will generate bt/btr/bts opcodes - note: they may be slow when applied on a memory location, but not on an integer value (register)


1.3.56. TBits64

TBits64 = set of 0..63;

Fast access to 64-bit integer bits
- compiler will generate bt/btr/bts opcodes - note: they may be slow when applied on a memory location, but not on a Int64 value (register)
- as used by GetBit64/SetBit64/UnSetBit64


1.3.57. TBits8

TBits8 = set of 0..7;

Fast access to 8-bit integer bits
- compiler will generate bt/btr/bts opcodes - note: they may be slow when applied on a memory location, but not on a byte value (register)


1.3.58. TBlock128

TBlock128 = array[0..3] of cardinal;

Store a 128-bit buffer
- e.g. an AES block
- consumes 16 bytes of memory


1.3.59. TCompareOperator

TCompareOperator = ( coEqualTo, coNotEqualTo, coLessThan, coLessThanOrEqualTo, coGreaterThan, coGreaterThanOrEqualTo );

The recognized operators for comparison functions results match


1.3.60. TDACnt

TDACnt = integer ;

Cross-compiler type used for dynarray reference counter
- FPC uses PtrInt/SizeInt, Delphi uses longint even on CPU64


1.3.61. TDALen

TDALen = PtrInt;

Cross-compiler type used for dynamic array length
- both FPC and Delphi uses PtrInt/NativeInt for dynamic array high/length


1.3.62. TDateTimeMS

TDateTimeMS = type TDateTime;

A type alias, which will be serialized as ISO-8601 with milliseconds
- i.e. 'YYYY-MM-DD hh:mm:ss.sss' or 'YYYYMMDD hhmmss.sss' format


1.3.63. TDateTimeMSDynArray

TDateTimeMSDynArray = array of TDateTimeMS;

A dynamic array of TDateTimeMS values


1.3.64. TDynArraySortCompare

TDynArraySortCompare = function(const A, B): integer;

Function prototype to be used for TDynArray Sort and Find method
- common functions exist for base types: see e.g. SortDynArrayBoolean, SortDynArrayByte, SortDynArrayWord, SortDynArrayInteger, SortDynArrayCardinal, SortDynArrayInt64, SortDynArrayQWord, SordDynArraySingle, SortDynArrayDouble, SortDynArrayAnsiString, SortDynArrayAnsiStringI, SortDynArrayUnicodeString, SortDynArrayUnicodeStringI, SortDynArrayString, SortDynArrayStringI
- any custom type (even records) can be compared then sort by defining such a custom function
- must return 0 if A=B, -1 if A<B, 1 if A>B
- simple types are compared within this unit (with proper optimized asm if possible), whereas more complex types are implemented in other units - e.g. SortDynArrayVariant/SortDynArrayVariantI are in mormot.core.variants and SortDynArrayPUtf8CharI/SortDynArrayStringI in mormot.core.text


1.3.65. TFloatNan

TFloatNan = ( fnNumber, fnNan, fnInf, fnNegInf );

The non-number values potentially stored in an IEEE floating point


1.3.66. TGuidShortString

TGuidShortString = string[38];

Stack-allocated ASCII string, used by GuidToShort() function


1.3.67. THash128

THash128 = array[0..15] of byte;

Store a 128-bit hash value
- e.g. a MD5 digest, or array[0..3] of cardinal (TBlock128)
- consumes 16 bytes of memory


1.3.68. THash128Array

THash128Array = array[ 0 .. MaxInt div SizeOf(THash128) - 1 ] of THash128;

Map an infinite array of 128-bit hash values
- each item consumes 16 bytes of memory


1.3.69. THash128DynArray

THash128DynArray = array of THash128;

Store several 128-bit hash values
- e.g. MD5 digests
- consumes 16 bytes of memory per item


1.3.70. THash160

THash160 = array[0..19] of byte;

Store a 160-bit hash value
- e.g. a SHA-1 digest
- consumes 20 bytes of memory


1.3.71. THash192

THash192 = array[0..23] of byte;

Store a 192-bit hash value
- consumes 24 bytes of memory


1.3.72. THash224

THash224 = array[0..27] of byte;

Store a 224-bit hash value
- consumes 28 bytes of memory


1.3.73. THash256

THash256 = array[0..31] of byte;

Store a 256-bit hash value
- e.g. a SHA-256 digest, a TEccSignature result, or array[0..7] of cardinal
- consumes 32 bytes of memory


1.3.74. THash256Array

THash256Array = array[ 0 .. MaxInt div SizeOf(THash256) - 1 ] of THash256;

Map an infinite array of 256-bit hash values
- each item consumes 32 bytes of memory


1.3.75. THash256DynArray

THash256DynArray = array of THash256;

Store several 256-bit hash values
- e.g. SHA-256 digests, TEccSignature results, or array[0..7] of cardinal
- consumes 32 bytes of memory per item


1.3.76. THash256RecDynArray

THash256RecDynArray = array of THash256Rec;

Store several 256-bit hash map variable records


1.3.77. THash384

THash384 = array[0..47] of byte;

Store a 384-bit hash value
- e.g. a SHA-384 digest
- consumes 48 bytes of memory


1.3.78. THash384DynArray

THash384DynArray = array of THash384;

Store several 384-bit hash values


1.3.79. THash512

THash512 = array[0..63] of byte;

Store a 512-bit hash value
- e.g. a SHA-512 digest, a TEccSignature result, or array[0..15] of cardinal
- consumes 64 bytes of memory


1.3.80. THash512Array

THash512Array = array[ 0 .. MaxInt div SizeOf(THash512) - 1 ] of THash512;

Map an infinite array of 512-bit hash values
- each item consumes 64 bytes of memory


1.3.81. THash512DynArray

THash512DynArray = array of THash512;

Store several 512-bit hash values
- e.g. SHA-512 digests, or array[0..15] of cardinal
- consumes 64 bytes of memory per item


1.3.82. THash512RecDynArray

THash512RecDynArray = array of THash512Rec;

Store several 256-bit hash map variable records


1.3.83. THasher

THasher = function(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;

Function prototype to be used for 32-bit hashing of an element
- it must return a cardinal hash, with as less collision as possible
- is the function signature of DefaultHasher and InterningHasher


1.3.84. THasher128

THasher128 = procedure(hash: PHash128; buf: PAnsiChar; len: cardinal);

Function prototype to be used for 128-bit hashing of an element
- the input hash buffer is used as seed, and contains the 128-bit result
- is the function signature of DefaultHasher128


1.3.85. THasher64

THasher64 = function(crc: QWord; buf: PAnsiChar; len: cardinal): QWord;

Function prototype to be used for 64-bit hashing of an element
- it must return a QWord hash, with as less collision as possible
- is the function signature of DefaultHasher64


1.3.86. TID

TID = type Int64;

A 64-bit identifier, as used for our ORM primary key, i.e. TOrm.ID
- also maps the SQLite3 64-bit RowID definition


1.3.87. TIDDynArray

TIDDynArray = array of TID;

Used to store a dynamic array of ORM primary keys, i.e. TOrm.ID


1.3.88. TIntCnt

TIntCnt = integer ;

Cross-compiler return type of IUnknown._AddRef/_Release methods
- used to reduce the $ifdef when implementing interfaces in Delphi and FPC


1.3.89. TIntelAvx10Vector

TIntelAvx10Vector = set of ( av128, av256, av512);

The supported AVX10 Converged Vector ISA bit sizes


1.3.90. TIntelCpuFeature

TIntelCpuFeature = ( cfFPU, cfVME, cfDE, cfPSE, cfTSC, cfMSR, cfPAE, cfMCE, cfCX8, cfAPIC, cf_d10, cfSEP, cfMTRR, cfPGE, cfMCA, cfCMOV, cfPAT, cfPSE36, cfPSN, cfCLFSH, cf_d20, cfDS, cfACPI, cfMMX, cfFXSR, cfSSE, cfSSE2, cfSS, cfHTT, cfTM, cfIA64, cfPBE, cfSSE3, cfCLMUL, cfDS64, cfMON, cfDSCPL, cfVMX, cfSMX, cfEST, cfTM2, cfSSSE3, cfCID, cfSDBG, cfFMA, cfCX16, cfXTPR, cfPDCM, cf_c16, cfPCID, cfDCA, cfSSE41, cfSSE42, cfX2A, cfMOVBE, cfPOPCNT, cfTSC2, cfAESNI, cfXS, cfOSXS, cfAVX, cfF16C, cfRAND, cfHYP, cfFSGS, cfTSCADJ, cfSGX, cfBMI1, cfHLE, cfAVX2, cfFDPEO, cfSMEP, cfBMI2, cfERMS, cfINVPCID, cfRTM, cfPQM, cfFPUSEG, cfMPX, cfPQE, cfAVX512F, cfAVX512DQ, cfRDSEED, cfADX, cfSMAP, cfAVX512IFMA, cfPCOMMIT, cfCLFLUSH, cfCLWB, cfIPT, cfAVX512PF, cfAVX512ER, cfAVX512CD, cfSHA, cfAVX512BW, cfAVX512VL, cfPREFW1, cfAVX512VBMI, cfUMIP, cfPKU, cfOSPKE, cfWAITPKG, cfAVX512VBMI2, cfCETSS, cfGFNI, cfVAES, cfVCLMUL, cfAVX512NNI, cfAVX512BITALG, cfTMEEN, cfAVX512VPC, cf_c15, cfFLP, cfMPX0, cfMPX1, cfMPX2, cfMPX3, cfMPX4, cfRDPID, cfKL, cfBUSLOCK, cfCLDEMOTE, cf_c26, cfMOVDIRI, cfMOVDIR64B, cfENQCMD, cfSGXLC, cfPKS, cf_d0, cfSGXKEYS, cfAVX512NNIW, cfAVX512MAPS, cfFSRM, cfUINTR, cf_d6, cf_d7, cfAVX512VP2I, cfSRBDS, cfMDCLR, cfTSXABRT, cf_d12, cfTSXFA, cfSER, cfHYBRID, cfTSXLDTRK, cf_d17, cfPCFG, cfLBR, cfIBT, cf_d21, cfAMXBF16, cfAVX512FP16, cfAMXTILE, cfAMXINT8, cfIBRSPB, cfSTIBP, cfL1DFL, cfARCAB, cfCORCAB, cfSSBD, cfSHA512, cfSM3, cfSM4, cfRAOINT, cfAVXVNNI, cfAVX512BF16, cfLASS, cfCMPCCXADD, cfAPMEL, cf_a9, cfFZLREPM, cfFSREPS, cfFSREPC, cf_a13, cf_a14, cf_a15, cf_a16, cfFRED, cfLKGS, cfWRMSRNS, cf_a20, cfAMXFP16, cfHRESET, cfAVXIFMA, cf_a24, cf_a25, cfLAM, cfMSRLIST, cf_a28, cf_a29, cf_a30, cf_a31, cf__d0, cf_d1, cf_d2, cf_d3, cfAVXVNN8, cfAVXNECVT, cf__d6, cf__d7, cfAMXCPLX, cf_d9, cfAVXVNNI16, cf_d11, cf__d12, cf_d13, cfPREFETCHI, cf_d15, cf_d16, cfUIRETUIF, cfCETSSS, cfAVX10, cf__d20, cf_APXF, cf_d22, cf_d23, cf_d24, cf_d25, cf_d26, cf_d27, cf_d28, cf_d29, cf_d30, cf_d31 );

The potential features, retrieved from an Intel/AMD CPU
- cf https://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits
- is defined on all platforms, so that e.g. an ARM desktop may browse Intel-generated logs using TSynLogFile from mormot.core.log.pas


1.3.91. TIntelCpuFeatures

TIntelCpuFeatures = set of TIntelCpuFeature;

All CPU features flags, as retrieved from an Intel/AMD CPU


1.3.92. TIntQry

TIntQry = HRESULT ;

Cross-compiler return type of IUnknown.QueryInterface method
- used to reduce the $ifdef when implementing interfaces in Delphi and FPC


1.3.93. ToByte

ToByte = byte;

Used as ToByte() to properly truncate any integer into 8-bit
- is defined as an inlined "and 255" function under ARM to work as expected


1.3.94. TPtrArrayKind

TPtrArrayKind = ( pakPointer, pakClass, pakClassSafe, pakInterface );

Used by PtrArrayDelete() to finalize an item


1.3.95. TPUtf8CharArray

TPUtf8CharArray = array[ 0 .. MaxInt div SizeOf(PUtf8Char) - 1 ] of PUtf8Char;

A Row/Col array of PUtf8Char, for containing sqlite3_get_table() result


1.3.96. TPUtf8CharDynArray

TPUtf8CharDynArray = array of PUtf8Char;

A dynamic array of PUtf8Char pointers


1.3.97. TRawUtf8DynArray

TRawUtf8DynArray = array of RawUtf8;

A dynamic array of UTF-8 encoded strings


1.3.98. TShort15

TShort15 = string[15];

Used e.g. by TSynSystemTime.ToTextDateShort


1.3.99. TShort16

TShort16 = string[16];

Used e.g. by PointerToHexShort/CardinalToHexShort/Int64ToHexShort/FormatShort16
- such result type would avoid a string allocation on heap, so are highly recommended e.g. when logging small pieces of information


1.3.100. TShort23

TShort23 = string[23];

Used e.g. by Int64ToHttpEtag


1.3.101. TShort31

TShort31 = string[31];

Used e.g. for SetThreadName/GetCurrentThreadName


1.3.102. TShort47

TShort47 = string[47];

A shortstring which only takes 48 bytes of memory


1.3.103. TShort64

TShort64 = string[64];

Not as good as ESynException used e.g. to serialize up to 256-bit as hexadecimal


1.3.104. TShort8

TShort8 = string[8];

Used e.g. for TTextWriter.AddShorter small text constants


1.3.105. TSqlRawBlob

TSqlRawBlob = RawBlob;

Backward compatibility types redirections


1.3.106. TStrCnt

TStrCnt = integer ;

Cross-compiler type used for string reference counter
- FPC and Delphi don't always use the same type


1.3.107. TStreamDynArray

TStreamDynArray = array of TStream;

A dynamic array of TStream instances


1.3.108. TStrLen

TStrLen = longint ;

Cross-compiler type used for string length
- FPC uses PtrInt/SizeInt, Delphi uses longint even on CPU64


1.3.109. TSynExtended

TSynExtended = extended;

The floating-point type to be used for best precision and speed
- will allow to fallback to double e.g. on x64 and ARM CPUs


1.3.110. TSynLogLevel

TSynLogLevel = ( sllNone, sllInfo, sllDebug, sllTrace, sllWarning, sllError, sllEnter, sllLeave, sllLastError, sllException, sllExceptionOS, sllMemory, sllStackTrace, sllFail, sllSQL, sllCache, sllResult, sllDB, sllHTTP, sllClient, sllServer, sllServiceCall, sllServiceReturn, sllUserAuth, sllCustom1, sllCustom2, sllCustom3, sllCustom4, sllNewRun, sllDDDError, sllDDDInfo, sllMonitoring );

The available logging events, as handled by mormot.core.log
- defined in mormot.core.base so that it may be used by the core units, even if mormot.core.log is not explicitely linked
- limited to 32 items, to efficiently fit in a 32-bit set
- sllInfo will log general information events
- sllDebug will log detailed debugging information
- sllTrace will log low-level step by step debugging information
- sllWarning will log unexpected values (not an error)
- sllError will log errors
- sllEnter will log every method start
- sllLeave will log every method exit
- sllLastError will log the GetLastError OS message
- sllException will log all exception raised - available since Windows XP
- sllExceptionOS will log all OS low-level exceptions (EDivByZero, ERangeError, EAccessViolation...)
- sllMemory will log memory statistics (in MB units)
- sllStackTrace will log caller's stack trace (it's by default part of TSynLogFamily.LevelStackTrace like sllError, sllException, sllExceptionOS, sllLastError and sllFail)
- sllFail was defined for TSynTestsLogged.Failed method, and can be used to log some customer-side assertions (may be notifications, not errors)
- sllSQL is dedicated to trace the SQL statements
- sllCache should be used to trace the internal caching mechanism
- sllResult could trace the SQL results, JSON encoded
- sllDB is dedicated to trace low-level database engine features
- sllHTTP could be used to trace HTTP process
- sllClient/sllServer could be used to trace some Client or Server process
- sllServiceCall/sllServiceReturn to trace some remote service or library
- sllUserAuth to trace user authentication (e.g. for individual requests)
- sllCustom* items can be used for any purpose
- sllNewRun will be written when a process opens a rotated log
- sllDDDError will log any DDD-related low-level error information
- sllDDDInfo will log any DDD-related low-level debugging information
- sllMonitoring will log the statistics information (if available), or may be used for real-time chat among connected people to ToolsAdmin


1.3.111. TSynLogLevelDynArray

TSynLogLevelDynArray = array of TSynLogLevel;

A dynamic array of logging event levels


1.3.112. TSynLogLevels

TSynLogLevels = set of TSynLogLevel;

Used to define a set of logging level abilities
- i.e. a combination of none or several logging event - stored as 32-bit
- e.g. use LOG_VERBOSE constant to log all events, or LOG_STACKTRACE to log all errors and exceptions


1.3.113. TSynLogProc

TSynLogProc = procedure(Level: TSynLogLevel; const Fmt: RawUtf8; const Args: array of const; Instance: TObject = nil) of object;

Callback definition used to abstractly log some events
- defined as TMethod to avoid dependency with the mormot.core.log unit
- match class procedure TSynLog.DoLog
- used e.g. by global variables like WindowsServiceLog in mormot.core.os or TCrtSocket.OnLog in mormot.net.sock


1.3.114. TThreadID

TThreadID = cardinal;

Used to store the handle of a system Thread


1.3.115. TTimeLog

TTimeLog = type Int64;

Fast bit-encoded date and time value
- see TTimeLog helper functions and types in mormot.core.datetime
- faster than Iso-8601 text and TDateTime, e.g. can be used as published property field in mORMot's TOrm (see also TModTime and TCreateTime)
- use internally for computation an abstract "year" of 16 months of 32 days of 32 hours of 64 minutes of 64 seconds - same as Iso8601ToTimeLog()
- use TimeLogFromDateTime/TimeLogToDateTime/TimeLogNow functions, or type-cast any TTimeLog value with the TTimeLogBits memory structure for direct access to its bit-oriented content (or via PTimeLogBits pointer)
- since TTimeLog type is bit-oriented, you can't just add or substract two TTimeLog values when doing date/time computation: use a TDateTime temporary conversion in such case:

 aTimestamp := TimeLogFromDateTime(IncDay(TimeLogToDateTime(aTimestamp)));

1.3.116. TTimeLogDynArray

TTimeLogDynArray = array of TTimeLog;

Dynamic array of TTimeLog
- recognized e.g. by TDynArray JSON serialization


1.3.117. TTVarRecDynArray

TTVarRecDynArray = array of TVarRec;

A dynamic array of TVarRec, i.e. could match an "array of const" parameter


1.3.118. TUnixMSTime

TUnixMSTime = type Int64;

Timestamp stored as millisecond-based Unix Time
- see Unix Time helper functions and types in mormot.core.datetime
- i.e. the number of milliseconds since 1970-01-01 00:00:00 UTC
- see TUnixTime for a second resolution Unix Timestamp
- use UnixMSTimeToDateTime/DateTimeToUnixMSTime functions to convert it to/from a regular TDateTime
- also one of the JavaScript date encodings


1.3.119. TUnixMSTimeDynArray

TUnixMSTimeDynArray = array of TUnixMSTime;

Dynamic array of timestamps stored as millisecond-based Unix Time


1.3.120. TUnixTime

TUnixTime = type Int64;

Timestamp stored as second-based Unix Time
- see Unix Time helper functions and types in mormot.core.datetime
- i.e. the number of seconds since 1970-01-01 00:00:00 UTC
- is stored as 64-bit value, so that it won't be affected by the "Year 2038" overflow issue
- see TUnixMSTime for a millisecond resolution Unix Timestamp
- use UnixTimeToDateTime/DateTimeToUnixTime functions to convert it to/from a regular TDateTime
- use UnixTimeUtc to return the current timestamp, using fast OS API call
- also one of the encodings supported by SQLite3 date/time functions


1.3.121. TUnixTimeDynArray

TUnixTimeDynArray = array of TUnixTime;

Dynamic array of timestamps stored as second-based Unix Time


1.3.122. TVarDataStaticArray

TVarDataStaticArray = array[ 0 .. MaxInt div SizeOf(TVarData) - 1 ] of TVarData;

A TVarData values array
- is not called TVarDataArray to avoid confusion with the corresponding type already defined in RTL Variants.pas, and used for custom late-binding


1.3.123. Ucs4CodePoint

Ucs4CodePoint = cardinal;

Store one 32-bit UCS4 CodePoint (with a better naming than UCS4 "Char")
- RTL's Ucs4Char is buggy, especially on oldest Delphi


1.3.124. unaligned

unaligned = Double;

Unaligned() will be defined and useful only on FPC ARM/Aarch64 plaforms


1.3.125. WinAnsiString

WinAnsiString = type AnsiString;

WinAnsiString is a WinAnsi-encoded AnsiString (code page 1252)
- use this type instead of System.String, which behavior changed between Delphi 2009 compiler and previous versions: our implementation is consistent and compatible with all versions of Delphi compiler
- all conversion to/from string or RawUtf8/UTF8String must be explicit on Delphi 7/2007, and it will be faster anyway to use our optimized functions from mormot.core.unicode.pas unit like StringToUtf8/Utf8ToString


1.4. Constants implemented in the mormot.core.base unit

1.4.1. ALLBITS_CARDINAL

ALLBITS_CARDINAL: array[1..32] of cardinal = ( 1 shl 1 - 1, 1 shl 2 - 1, 1 shl 3 - 1, 1 shl 4 - 1, 1 shl 5 - 1, 1 shl 6 - 1, 1 shl 7 - 1, 1 shl 8 - 1, 1 shl 9 - 1, 1 shl 10 - 1, 1 shl 11 - 1, 1 shl 12 - 1, 1 shl 13 - 1, 1 shl 14 - 1, 1 shl 15 - 1, 1 shl 16 - 1, 1 shl 17 - 1, 1 shl 18 - 1, 1 shl 19 - 1, 1 shl 20 - 1, 1 shl 21 - 1, 1 shl 22 - 1, 1 shl 23 - 1, 1 shl 24 - 1, 1 shl 25 - 1, 1 shl 26 - 1, 1 shl 27 - 1, 1 shl 28 - 1, 1 shl 29 - 1, 1 shl 30 - 1, $7fffffff, $ffffffff);

Constant array used by GetAllBits() function (when inlined)


1.4.2. CODEPAGE_LATIN1

CODEPAGE_LATIN1 = CP_LATIN1;

Use rather CP_LATIN1 with mORMot 2


1.4.3. CODEPAGE_US

CODEPAGE_US = CP_WINANSI;

Use rather CP_WINANSI with mORMot 2


1.4.4. CP_ACP

CP_ACP = 0;

Internal Code Page for System AnsiString encoding


1.4.5. CP_LATIN1

CP_LATIN1 = 819;

Latin-1 ISO/IEC 8859-1 Code Page
- map low 8-bit Unicode CodePoints


1.4.6. CP_OEM

CP_OEM = 1;

Internal Code Page for System Console encoding


1.4.7. CP_RAWBLOB

CP_RAWBLOB = 65534;

Fake code page used to recognize RawBlob
- RawBlob internal code page will be CP_RAWBYTESTRING = 65535, but our ORM will identify the RawBlob type and unserialize it using CP_RAWBLOB instead
- TJsonWriter.AddAnyAnsiBuffer will recognize it and use Base-64 encoding


1.4.8. CP_RAWBYTESTRING

CP_RAWBYTESTRING = 65535;

Internal Code Page for RawByteString undefined string


1.4.9. CP_UTF16

CP_UTF16 = 1200;

Internal Code Page for UTF-16 Unicode encoding
- used e.g. for Delphi 2009+ UnicodeString=String type


1.4.10. CP_UTF8

CP_UTF8 = 65001;

Internal Code Page for UTF-8 Unicode encoding
- as used by RawUtf8 and all our internal framework text process


1.4.11. CP_WINANSI

CP_WINANSI = 1252;

US English Windows Code Page, i.e. WinAnsi standard character encoding


1.4.12. CURR_RES

CURR_RES = 10000;

Used e.g. to convert a currency (via PInt64) into a double
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.4.13. DOUBLE_SAME

DOUBLE_SAME = 1E-11;

A typical error allowed when working with double floating-point values
- 1E-12 is too small, and triggers sometimes some unexpected errors; FPC RTL uses 1E-4 so we are paranoid enough


1.4.14. FindNonVoid

FindNonVoid: array[boolean] of TFindNonVoid = ( FindNonVoidRawUtf8I, FindNonVoidRawUtf8);

Raw internal methods for case sensitive (or not) search for a RawUtf8
- expects non-void RawUtf8 values, with ASCII-7 encoding, e.g. as with TDocVariantData.GetValueIndex() property names


1.4.15. GUID_NULL

GUID_NULL: TGuid = ();

A TGuid containing '{00000000-0000-0000-0000-00000000000}'


1.4.16. KNUTH_HASH32_MUL

KNUTH_HASH32_MUL = $9E3779B1;

Knuth's magic number for hashing a 32-bit value, using the golden ratio
- then use the result high bits, i.e. via "shr" not via "and"
- for instance, mormot.core.log uses it to hash the TThreadID:

 hash := cardinal(cardinal(id) * KNUTH_HASH32_MUL) shr (32 - MAXLOGTHREADBITS);

1.4.17. KNUTH_HASH64_MUL

KNUTH_HASH64_MUL = $9E3779B97F4A7C15;

Knuth's magic number for hashing a 64-bit value, using the golden ratio


1.4.18. KNUTH_HASHPTR_MUL

KNUTH_HASHPTR_MUL = KNUTH_HASH32_MUL;

Knuth's magic number for hashing a PtrUInt, using the golden ratio


1.4.19. LOG_TRACEWARNING

LOG_TRACEWARNING: array[boolean] of TSynLogLevel = ( sllTrace, sllWarning);

May be used to log as Trace or Warning event, depending on an Error: boolean


1.4.20. NULCHAR

NULCHAR: AnsiChar = #0;

Used to mark the end of ASCIIZ buffer, or return a void ShortString


1.4.21. NullVarData

NullVarData: TVarData = (VType: varNull);

A slightly faster alternative to Variants.Null function with TVarData


1.4.22. POINTERAND

POINTERAND = 3 ;

Could be used to compute the bitmask of a pointer integer


1.4.23. POINTERBITS

POINTERBITS = 32 ;

Could be used to check all bits on a pointer


1.4.24. POINTERBYTES

POINTERBYTES = 4 ;

Could be used to check all bytes on a pointer


1.4.25. POINTERSHR

POINTERSHR = 2 ;

Could be used to compute the index in a pointer list from its byte position


1.4.26. POINTERSHRBITS

POINTERSHRBITS = 5 ;

Could be used to compute the index in a pointer list from its bits position


1.4.27. POW10

POW10: TPow10 = ( 1E-31, 1E-30, 1E-29, 1E-28, 1E-27, 1E-26, 1E-25, 1E-24, 1E-23, 1E-22, 1E-21, 1E-20, 1E-19, 1E-18, 1E-17, 1E-16, 1E-15, 1E-14, 1E-13, 1E-12, 1E-11, 1E-10, 1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1, 1E0, 1E1, 1E2, 1E3, 1E4, 1E5, 1E6, 1E7, 1E8, 1E9, 1E10, 1E11, 1E12, 1E13, 1E14, 1E15, 1E16, 1E17, 1E18, 1E19, 1E20, 1E21, 1E22, 1E23, 1E24, 1E25, 1E26, 1E27, 1E28, 1E29, 1E30, 1E31, 0, -1, 1E0, 1E32, 1E64, 1E96, 1E128, 1E160, 1E192, 1E224, 1E256, 1E288, 1E320, 1E-0, 1E-32, 1E-64, 1E-96, 1E-128, 1E-160, 1E-192, 1E-224, 1E-256, 1E-288, 1E-320);

Most common 10 ^ exponent constants, ending with values for HugePower10*()


1.4.28. SYNOPSE_FRAMEWORK_FULLVERSION

SYNOPSE_FRAMEWORK_FULLVERSION = SYNOPSE_FRAMEWORK_VERSION ;

A text including the version and the main active conditional options
- usefull for low-level debugging purpose


1.4.29. SYNOPSE_FRAMEWORK_NAME

SYNOPSE_FRAMEWORK_NAME = 'mORMot';

The full text of the Synopse mORMot framework
- note: we don't supply full version number with build revision for HTTP servers, to reduce potential attack surface


1.4.30. SYNOPSE_FRAMEWORK_VERSION

SYNOPSE_FRAMEWORK_VERSION = '2.2.7976' ;

The corresponding version of the mORMot framework, as '2.#.#'
- 2nd digit is minor version, increased at each framework release, when adding functionality in a stable enough manner
- 3rd digit is a globally increasing git commit number (as generated by the commit.sh script) - so won't be reset when minor is up


1.4.31. TwoDigitLookup

TwoDigitLookup: packed array[0..99] of array[1..2] of AnsiChar = ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99');

Fast lookup table for converting any decimal number from 0 to 99 into their ASCII equivalence


1.4.32. varNativeString

varNativeString = varString;

This variant type will map the current string type
- depending on the compiler string definition (UnicodeString or AnsiString)


1.4.33. varOleClsid

varOleClsid = 72;

Map the Windows VT_CLSID extended VARENUM, i.e. a by-reference PGuid


1.4.34. varOleFileTime

varOleFileTime = 64;

Map the Windows VT_FILETIME extended VARENUM, i.e. a 64-bit TFileTime
- also detected and handled by VariantToDateTime


1.4.35. varOleInt

varOleInt = 22;

Map the Windows VT_INT extended VARENUM, i.e. a 32-bit signed integer
- also detected and handled by VariantToInteger/VariantToInt64


1.4.36. varOlePAnsiChar

varOlePAnsiChar = 30;

Map the Windows VT_LPSTR extended VARENUM, i.e. a PAnsiChar
- also detected and handled by VariantToUtf8


1.4.37. varOlePWideChar

varOlePWideChar = 31;

Map the Windows VT_LPWSTR extended VARENUM, i.e. a PWideChar
- also detected and handled by VariantToUtf8


1.4.38. varOleUInt

varOleUInt = 23;

Map the Windows VT_UINT extended VARENUM, i.e. a 32-bit unsigned integer
- also detected and handled by VariantToInteger/VariantToInt64


1.4.39. varSynUnicode

varSynUnicode = varOleStr;

This variant type will map the current SynUnicode type
- depending on the compiler version


1.4.40. varWord64

varWord64 = 21;

Unsigned 64bit integer variant type
- currently called varUInt64 in Delphi (not defined in older versions), and varQWord in FPC


1.4.41. VTYPE_NUMERIC

VTYPE_NUMERIC = [varSmallInt .. varDouble, varCurrency, varBoolean .. varOleUInt];

Those TVarData.VType values are meant to be number values and need no escape


1.4.42. VTYPE_SIMPLE

VTYPE_SIMPLE = [varEmpty..varDate, varBoolean, varShortInt..varWord64, varOleInt, varOleUInt, varOlePAnsiChar, varOlePWideChar, varOleFileTime, varUnknown];

Those TVarData.VType values are meant to be direct values


1.4.43. VTYPE_STATIC

VTYPE_STATIC = $BFE8;

Bitmask used by our inlined VarClear() to avoid unneeded VarClearProc()


1.4.44. _DACNT

_DACNT = SizeOf(TDACnt) + _DALEN;

Cross-compiler negative offset to TDynArrayRec.refCnt field
- to be used inlined e.g. as PDACnt(PAnsiChar(Values) - _DACNT)^


1.4.45. _DALEN

_DALEN = SizeOf(TDALen);

Cross-compiler negative offset to TDynArrayRec.high/length field
- to be used inlined e.g. as

 PDALen(PAnsiChar(Values) - _DALEN)^ + _DAOFF

- both FPC and Delphi uses PtrInt/NativeInt for dynamic array high/length


1.4.46. _DAMAXSIZE

_DAMAXSIZE = $5fffffff;

In-memory TBytes process will allow up to 800 MB
- used as high limit e.g. for TBufferWriter.FlushToBytes
- even if a dynamic array can handle PtrInt length, consider other patterns


1.4.47. _DAOFF

_DAOFF = 0 ;

Cross-compiler adjuster to get length from TDynArrayRec.high/length field


1.4.48. _DARECSIZE

_DARECSIZE = SizeOf(TDynArrayRec);

Used to calc the beginning of memory allocation of a dynamic array


1.4.49. _STRCNT

_STRCNT = SizeOf(TStrCnt) + _STRLEN;

Cross-compiler negative offset to TStrRec.refCnt field
- to be used inlined e.g. as PStrCnt(p - _STRCNT)^


1.4.50. _STRLEN

_STRLEN = SizeOf(TStrLen);

Cross-compiler negative offset to TStrRec.length field
- to be used inlined e.g. as PStrLen(p - _STRLEN)^


1.4.51. _STRMAXSIZE

_STRMAXSIZE = $5fffffff;

In-memory string process will allow up to 800 MB
- used as high limit e.g. for TBufferWriter over a TRawByteStringStream
- Delphi strings have a 32-bit length so you should change your algorithm
- even if FPC on CPU64 can handle bigger strings, consider other patterns


1.4.52. _STRRECSIZE

_STRRECSIZE = SizeOf(TStrRec);

CodePage offset = string header size
- used to calc the beginning of memory allocation of a string


1.5. Functions or procedures implemented in the mormot.core.base unit

Functions or proceduresDescription
AddGuidAppend one TGuid item to a TGuid dynamic array
AddHash128Add a 128-bit item in an array of such values
AddInt64Add a 64-bit integer value at the end of a dynamic array
AddInt64Add a 64-bit integer value at the end of a dynamic array of integers
AddInt64Add a 64-bit integer array at the end of a dynamic array
AddInt64OnceIf not already existing, add a 64-bit integer value to a dynamic array
AddInt64SortedIf not already existing, add a 64-bit integer value to a sorted dynamic array
AddIntegerAdd an integer array at the end of a dynamic array of integer
AddIntegerAdd an integer value at the end of a dynamic array of integers
AddIntegerAdd an integer value at the end of a dynamic array of integers
AddIntegerAdd an integer value at the end of a dynamic array of integers
AddPtrUIntAdd a pointer-sized integer array at the end of a dynamic array
AddSortedIntegerAdd an integer value in a sorted dynamic array of integers
AddSortedIntegerAdd an integer value in a sorted dynamic array of integers
AddWordAdd a 16-bit integer value at the end of a dynamic array of integers
AndMemoryLogical AND of two memory buffers
Ansi7StringToShortStringDirect conversion of an ANSI-7 AnsiString into an ShortString
AppendShortSimple concatenation of a ShortString text into a shorstring
AppendShortAnsi7StringSimple concatenation of an ANSI-7 AnsiString into a shorstring
AppendShortBufferSimple concatenation of a #0 ending text into a shorstring
AppendShortByteHexSimple concatenation of a byte as hexadecimal into a shorstring
AppendShortCardinalSimple concatenation of a 32-bit unsigned integer as text into a shorstring
AppendShortCharSimple concatenation of a character into a shorstring
AppendShortInt64Simple concatenation of a 64-bit integer as text into a shorstring
BitsToBytesCompute how many bytes are needed to store a given number of bits
BSRdwordReturn the position of the leftmost set bit in a 32-bit value
BSRqwordReturn the position of the leftmost set bit in a 64-bit value
bswap32Convert the endianness of a given unsigned 32-bit integer into BigEndian
bswap64Convert the endianness of a given unsigned 64-bit integer into BigEndian
bswap64arrayConvert the endianness of an array of unsigned 64-bit integer into BigEndian
BufferLineLengthCompute the line length from a size-delimited source array of chars
ByteScanIndexFast search of an unsigned byte value position in a byte array
ClassNameShortJust a wrapper around vmtClassName to avoid a string conversion
ClassNameShortJust a wrapper around vmtClassName to avoid a string conversion
ClassToTextJust a wrapper around vmtClassName to avoid a string conversion
ClearVariantForStringInternal efficient wrapper of VarClear() + set VType=varString and VAny=nil
CompareBufOverload wrapper of MemCmp() to compare a RawByteString vs a memory buffer
CompareBufOverload wrapper to SortDynArrayRawByteString(P1, P2)
CompareCardinalA comparison function for sorting 32-bit unsigned integer values
CompareFloatA comparison function for sorting IEEE 754 double precision values
CompareInt64A comparison function for sorting 64-bit signed integer values
CompareIntegerA comparison function for sorting 32-bit signed integer values
CompareMemOur fast version of CompareMem()
CompareMemSmallA CompareMem()-like function designed for small (a few bytes) content
ComparePointerA comparison function for sorting 32/64-bit pointers as unsigned values
ComparePtrIntA comparison function for sorting 32/64-bit signed integer values
CompareQWordA comparison function for sorting 64-bit unsigned integer values
CompressSynLZCompress a data content using the SynLZ algorithm
CompressSynLZGetHash32Return the Hash32() 32-bit CRC of CompressSynLZ() uncompressed data
crc128cCompute a 128-bit checksum on the supplied buffer, cascading two crc32c
crc16Compute CRC16-CCITT checkum on the supplied buffer
crc256cCompute a 256-bit checksum on the supplied buffer using crc32c
crc32c128Compute a 128-bit CRC of any binary buffers
crc32cBy4fastPure pascal function implementing crc32cBy4()
crc32cfastCompute CRC32C checksum on the supplied buffer on processor-neutral code
crc32cHashCompute a 32-bit hash of any array of bytes using the CRC32C checksum
crc32cHashCompute a 32-bit hash of any string using the CRC32C checksum
crc32cinlinedCompute CRC32C checksum on the supplied buffer using inlined code
crc32csse42Defined here for mormot.test.base only
crc32ctwiceExpand a CRC32C checksum on the supplied buffer for 64-bit hashing
crc32fastCompute CRC32 checksum on the supplied buffer on processor-neutral code
crc63cCompute CRC63C checksum on the supplied buffer, cascading two crc32c
crc64cCompute CRC64C checksum on the supplied buffer, cascading two crc32c
crcblockfastComputation of our 128-bit CRC of a 128-bit binary buffer without SSE4.2
crcblocksfastCompute a proprietary 128-bit CRC of 128-bit binary buffers
CurrencyToDoubleConvert a currency value pointer into a double
CurrencyToDoubleConvert a currency value pointer into a double
CurrencyToDoubleConvert a currency value into a double
CurrencyToInt64Convert a currency value into a Int64
CurrencyToVariantFill a variant value from a currency value
DACntAddLow-level dynarray reference counter process
DACntDecFreeLow-level dynarray reference counter unprocess
DateTimeToIsoStringUse the RTL to return a date/time as ISO-8601 text
DefaultHashCompute a 32-bit hash of any string using DefaultHasher()
DefaultHashCompute a 32-bit hash of any array of bytes using DefaultHasher()
DeleteInt64Delete any 64-bit integer in Values[]
DeleteInt64Delete any 64-bit integer in Values[]
DeleteIntegerDelete any 32-bit integer in Values[]
DeleteIntegerDelete any 32-bit integer in Values[]
DeleteWordDelete any 16-bit integer in Values[]
Div100Simple wrapper to efficiently compute both division and modulo per 100
DoubleToCurrencyConvert a double value into a currency
DoubleToCurrencyConvert a double value into a currency
DoubleToCurrencyConvert a double value into a currency
DynArrayFakeLengthLike SetLength() but without any memory resize - WARNING: len should be > 0
DynArrayHashTableAdjustInternal hash table adjustment as called from TDynArrayHasher.HashDelete
DynArrayHashTableAdjust16DynArrayHashTableAdjust() version for 16-bit HashTable[] - SSE2 asm on x86_64
EnsureRawUtf8Ensure the supplied variable will have a CP_UTF8 - making it unique if needed
EnsureRawUtf8Ensure the supplied variable will have a CP_UTF8 - making it unique if needed
EqualBufOverload wrapper to SortDynArrayRawByteString(P1, P2) = 0
EventEqualsCompare two TMethod instances
ExchgLow-level inlined function for exchanging two memory buffers
ExchgPointerLow-level inlined function for exchanging two pointers
ExchgPointersLow-level inlined function for exchanging two sets of pointers
ExchgVariantLow-level inlined function for exchanging two variants
FakeCodePageInternal function which could be used instead of SetCodePage() if RefCnt = 1
FakeLengthInternal function which could be used instead of SetLength() if RefCnt = 1
FakeLengthInternal function which could be used instead of SetLength() if RefCnt = 1
FakeLengthInternal function which could be used instead of SetLength() if RefCnt = 1
FakeSetLengthInternal function which could be used instead of SetLength() if RefCnt = 1
FakeSetLengthInternal function which could be used instead of SetLength() if RefCnt = 1
FastAssignNewAssign any constant or already ref-counted AnsiString/RawUtf8
FastAssignNewNotVoidInternal function to assign any constant or ref-counted AnsiString/RawUtf8
FastAssignUtf8Internal function which assign src to dest, force CP_UTF8 and set src to ''
FastFindInt64SortedFast O(log(n)) binary search of a 64-bit signed integer value in a sorted array
FastFindIntegerSortedFast O(log(n)) binary search of an integer value in a sorted integer array
FastFindIntegerSortedFast O(log(n)) binary search of an integer value in a sorted integer array
FastFindPointerSortedFast O(log(n)) binary search of a pointer value in a sorted array
FastFindPtrIntSortedFast O(log(n)) binary search of a PtrInt value in a sorted array
FastFindQWordSortedFast O(log(n)) binary search of a 64-bit unsigned integer value in a sorted array
FastFindWordSortedFast O(log(n)) binary search of a 16-bit unsigned integer value in a sorted array
FastLocateIntegerSortedRetrieve the index where to insert an integer value in a sorted integer array
FastLocateWordSortedRetrieve the index where to insert a word value in a sorted word array
FastNewRawByteStringEquivalence to SetString(s,nil,len) function to allocate a new RawByteString
FastNewStringInternal function used by FastSetString/FastSetStringCP
FastSearchIntegerSortedRetrieve the matching index or where to insert an integer value
FastSetRawByteStringEquivalence to SetString(s,pansichar,len) function but from a raw pointer
FastSetStringEquivalence to SetString(s,pansichar,len) function but from a raw pointer
FastSetStringFaster equivalence to SetString(s,nil,len) function
FastSetStringCPEquivalence to SetString(s,pansichar,len) function with a specific code page
FillAnsiStringFromRandomInternal function used e.g. by TLecuyer.FillShort/FillShort31
FillcharFastOur fast version of FillChar() on Intel/AMD
FillIncreasingFill some values with i,i+1,i+2...i+Count-1
FillRandomFill some 32-bit memory buffer with values from the gsl_rng_taus2 generator
FillZeroFill all 64 bytes of this 512-bit buffer with zero
FillZeroFill all 32 bytes of this 256-bit buffer with zero
FillZeroFill a TGuid with 0
FillZeroFill all 20 bytes of this 160-bit buffer with zero
FillZeroFill all 16 bytes of this 128-bit buffer with zero
FillZeroFill all entries of a supplied array of 64-bit integers with 0
FillZeroFill all bytes of a memory buffer with zero
FillZeroFill all 32 bytes of this 384-bit buffer with zero
FillZeroFill all entries of a supplied array of 32-bit integers with 0
FillZeroSmallFill first bytes of a memory buffer with zero
FindNonVoidRawUtf8Raw internal method as published by FindNonVoid[false]
FindNonVoidRawUtf8IRaw internal method as published by FindNonVoid[true]
FindPropNameReturn the case-insensitive ASCII 7-bit index of Value in non-void Values[]
FindPropNameReturn the index of Value in Values[], -1 if not found
fnv32Simple FNV-1a hashing function
FreeAndNilSafeSame as FreeAndNil() but catching and ignoring any exception
FromI32Initializes a dynamic array from a set of 32-bit integer signed values
FromI64Initializes a dynamic array from a set of 64-bit integer signed values
FromU32Initializes a dynamic array from a set of 32-bit integer unsigned values
FromU64Initializes a dynamic array from a set of 64-bit integer unsigned values
gcdCompute GCD of two integers using modulo-based Euclidean algorithm
GetAllBitsReturns TRUE if all BitCount bits are set in the input 32-bit cardinal
GetBitRetrieve a particular bit status from a bit array
GetBit64Retrieve a particular bit status from a 64-bit integer bits (max aIndex is 63)
GetBitPtrRetrieve a particular bit status from a bit array
GetBitsCountCompute the number of bits set in a bit array
GetBitsCountPasPure pascal version of GetBitsCountPtrInt()
GetBitsCountSSE42Defined here for mormot.test.base only
GetBooleanGet a boolean value stored as 'true'/'false' text in input variable
GetBooleanGet a boolean value stored as 'true'/'false' text in P^
GetCardinalGet the unsigned 32-bit integer value stored in P^
GetCardinalGet the unsigned 32-bit integer value stored in P^
GetCardinalDefGet the unsigned 32-bit integer value stored in P^
GetCardinalWGet the unsigned 32-bit integer value stored as Unicode string in P^
GetClassParentJust a wrapper around vmtParent to avoid a function call
GetExtendedGet the extended floating point value stored in P^
GetExtendedGet the extended floating point value stored in P^
GetInt64Get the 64-bit integer value stored in P^
GetInt64Get the 64-bit signed integer value stored in P^
GetInt64BoolGet the 64-bit integer value from P^, recognizing true/false/yes/no input
GetInt64DefGet the 64-bit integer value stored in P^
GetIntegerGet the signed 32-bit integer value stored in P^..PEnd^
GetIntegerGet the signed 32-bit integer value stored in P^
GetIntegerGet the signed 32-bit integer value stored in P^
GetIntegerDefGet the signed 32-bit integer value stored in P^
GetMemAlignedInitialize a RawByteString, ensuring returned "aligned" pointer is 16-bytes aligned
GetQWordGet the 64-bit unsigned integer value stored in P^
GetTrueReturn 1 if 'TRUE' or 'YES', or 0 otherwise
GotoNextControlCharFast go to the first char <= #13
GotoNextLineFast go to next text line, ended by #13 or #13#10
Hash128IndexFast O(n) search of a 128-bit item in an array of such values
Hash128To64Combine/reduce a 128-bit hash into a 64-bit hash
Hash256IndexFast O(n) search of a 256-bit item in an array of such values
Hash32Our custom efficient 32-bit hash/checksum function
Hash32Our custom efficient 32-bit hash/checksum function
HasHWAesCross-platform wrapper function to check AES HW support on Intel or ARM
HugePower10NegLow-level computation of 10 ^ negative exponent, if POW10[] is not enough
HugePower10PosLow-level computation of 10 ^ positive exponent, if POW10[] is not enough
InsertIntegerInsert an integer value at the specified index position of a dynamic array of integers
Int64ScanFast search of an integer position in a 64-bit integer array
Int64ScanExistsFast search of an integer value in a 64-bit integer array
Int64ScanIndexFast search of an integer position in a signed 64-bit integer array
Int64ToCurrencyConvert a Int64 value into a currency
Int64ToCurrencyConvert a Int64 value into a currency
IntegerScanFast search of an unsigned integer item in a 32-bit integer array
IntegerScanExistsFast search of an unsigned integer in a 32-bit integer array
IntegerScanIndexFast search of an unsigned integer position in a 32-bit integer array
InterfaceArrayAddWrapper to add an item to a T*InterfaceArray dynamic array storage
InterfaceArrayAddCountWrapper to add an item to a T*InterfaceArray dynamic array storage
InterfaceArrayAddOnceWrapper to add once an item to a T*InterfaceArray dynamic array storage
InterfaceArrayDeleteWrapper to delete an item in a T*InterfaceArray dynamic array storage
InterfaceArrayDeleteWrapper to delete an item in a T*InterfaceArray dynamic array storage
InterfaceArrayFindWrapper to search an item in a T*InterfaceArray dynamic array storage
InterfaceNilSafeSame as aInterface := nil but ignoring any exception
InterfacesNilSafeSame as aInterface := nil but ignoring any exception
InterlockedDecrementCompatibility function, to be implemented according to the running CPU
InterlockedIncrementCompatibility function, to be implemented according to the running CPU
IsAnsiCompatibleReturn TRUE if the supplied text only contains 7-bits Ansi characters
IsAnsiCompatibleReturn TRUE if the supplied buffer only contains 7-bits Ansi characters
IsAnsiCompatibleReturn TRUE if the supplied buffer only contains 7-bits Ansi characters
IsAnsiCompatibleWReturn TRUE if the supplied UTF-16 buffer only contains 7-bits Ansi characters
IsAnsiCompatibleWReturn TRUE if the supplied UTF-16 buffer only contains 7-bits Ansi characters
IsEqualReturns TRUE if all 20 bytes of both 160-bit buffers do match
IsEqualReturns TRUE if all 16 bytes of both 128-bit buffers do match
IsEqualReturns TRUE if all 48 bytes of both 384-bit buffers do match
IsEqualReturns TRUE if all 64 bytes of both 512-bit buffers do match
IsEqualReturns TRUE if all bytes of both buffers do match
IsEqualReturns TRUE if all 32 bytes of both 256-bit buffers do match
IsEqualGuidCompare two TGuid values
IsEqualGuidCompare two TGuid values
IsEqualGuidArrayReturns the index of a matching TGuid in an array
IsNullGuidCheck if a TGuid value contains only 0 bytes
IsZeroReturns TRUE if all 16 bytes of this 128-bit buffer equal zero
IsZeroReturns TRUE if all 48 bytes of this 384-bit buffer equal zero
IsZeroReturns TRUE if Value is nil or all supplied Values[] equal 0
IsZeroReturns TRUE if all 64 bytes of this 512-bit buffer equal zero
IsZeroReturns TRUE if all bytes equal zero
IsZeroReturns TRUE if all 20 bytes of this 160-bit buffer equal zero
IsZeroReturns TRUE if Value is nil or all supplied Values[] equal 0
IsZeroReturns TRUE if all 32 bytes of this 256-bit buffer equal zero
IsZeroSmallReturns TRUE if all of a few bytes equal zero
KahanSumCompute the sum of values, using a running compensation for lost low-order bits
kr32Standard Kernighan & Ritchie hash from "The C programming Language", 3rd edition
LecuyerReturn the 32-bit Pierre L'Ecuyer software generator for the current thread
LecuyerEncryptCipher/uncipher some memory buffer using a 64-bit seed and Pierre L'Ecuyer's algorithm, and its gsl_rng_taus2 generator
LockedAddFast atomic addition operation on a pointer-sized integer value
LockedAdd32Fast atomic addition operation on a 32-bit integer value
LockedDecFast atomic substraction operation on a pointer-sized integer value
LockedDec32Slightly faster than InterlockedDecrement() when you don't need the result
LockedExcFast atomic compare-and-swap operation on a pointer-sized integer value
LockedInc32Slightly faster than InterlockedIncrement() when you don't need the result
LockedInc64Slightly faster than InterlockedIncrement64()
MemCmpBinary comparison of buffers, returning <0, 0 or >0 results
MoveAndZeroPerform a MoveFast then fill the Source buffer with zeros
MoveByOneMove() with one-by-one byte copy
MoveFastOur fast version of move() on Intel/AMD
MoveSwapCopy one memory buffer to another, swapping the bytes order
mul64x64Fast computation of two 64-bit unsigned integers into a 128-bit value
MultiEventAddLow-level wrapper to add a callback to a dynamic list of events
MultiEventFindLow-level wrapper to check if a callback is in a dynamic list of events
MultiEventMergeLow-level wrapper to add one or several callbacks from another list of events
MultiEventRemoveLow-level wrapper to remove a callback from a dynamic list of events
MultiEventRemoveLow-level wrapper to remove a callback from a dynamic list of events
NextGrowCompute the new capacity when expanding an array of items
ObjArrayAddWrapper to add an item to a T*ObjArray dynamic array storage
ObjArrayAddCountWrapper to add an item to a T*ObjArray dynamic array storage
ObjArrayAddFromWrapper to add items to a T*ObjArray dynamic array storage
ObjArrayAddOnceWrapper to add once an item to a T*ObjArray dynamic array storage
ObjArrayAddOnceWrapper to add once an item to a T*ObjArray dynamic array storage and Count
ObjArrayAddOnceFrom
ObjArrayAppendWrapper to add and move items to a T*ObjArray dynamic array storage
ObjArrayClearWrapper to release all items stored in a T*ObjArray dynamic array
ObjArrayClearWrapper to release all items stored in a T*ObjArray dynamic array
ObjArrayClearWrapper to release all items stored in a T*ObjArray dynamic array
ObjArrayDeleteWrapper to delete an item in a T*ObjArray dynamic array storage
ObjArrayDeleteWrapper to delete an item in a T*ObjArray dynamic array storage
ObjArrayDeleteWrapper to delete an item in a T*ObjArray dynamic array storage
ObjArrayFindWrapper to search an item in a T*ObjArray dynamic array storage
ObjArrayFindWrapper to search an item in a T*ObjArray dynamic array storage
ObjArrayNotNilCountWrapper to count all not nil items in a T*ObjArray dynamic array storage
ObjArrayObjArrayClearWrapper to release all items stored in an array of T*ObjArray dynamic array
ObjArraysClearWrapper to release all items stored in several T*ObjArray dynamic arrays
ObjArraySetLengthWrapper to set the length of a T*ObjArray dynamic array storage
OrMemoryLogical OR of two memory buffers
PosCharFast retrieve the position of a given character in a #0 ended buffer
PosCharFast retrieve the position of a given character in a #0 ended buffer
PosExFaster RawUtf8 Equivalent of standard StrUtils.PosEx
PosExCharOptimized version of PosEx() with search text as one AnsiChar
PosExStringOur own PosEx() function dedicated to RTL string process
PropNameEqualsCase-insensitive comparison of two shortstrings only containing ASCII 7-bit
PropNameEqualsDelphi has troubles inlining goto/label case-insensitive comparison of two RawUtf8 only containing ASCII 7-bit
PtrArrayAddWrapper to add an item to a array of pointer dynamic array storage
PtrArrayAddWrapper to add an item to a array of pointer dynamic array storage
PtrArrayAddOnceWrapper to add once an item to a array of pointer dynamic array storage
PtrArrayAddOnceWrapper to add once an item to a array of pointer dynamic array storage
PtrArrayDeleteWrapper to delete an item from a array of pointer dynamic array storage
PtrArrayDeleteWrapper to delete an item from a array of pointer dynamic array storage
PtrArrayFindWrapper to find an item to a array of pointer dynamic array storage
PtrArrayInsertWrapper to insert an item to a array of pointer dynamic array storage
PtrUIntScanFast search of a pointer-sized unsigned integer in an pointer-sized integer array
PtrUIntScanExistsFast search of a pointer-sized unsigned integer position in an pointer-sized integer array
PtrUIntScanIndexFast search of a pointer-sized unsigned integer position in an pointer-sized integer array
QuickSortDoubleSort a double array, low values first
QuickSortInt64Sort a 64-bit integer array, low values first
QuickSortInt64Sort a 64-bit signed integer array, low values first
QuickSortIntegerSort an integer array, low values first
QuickSortIntegerSort an integer array, low values first
QuickSortIntegerSort an integer array, low values first
QuickSortPointerSort a pointer array, low values first
QuickSortPtrIntSort a PtrInt array, low values first
QuickSortQWordSort a 64-bit unsigned integer array, low values first
QuickSortWordSort a 16-bit unsigned integer array, low values first
QWordScanIndexFast search of an integer position in an unsigned 64-bit integer array
RaiseStreamErrorRaise a EStreamError exception - e.g. from TSynMemoryStream.Write
Random31Fast compute of some 31-bit random value, using the gsl_rng_taus2 generator
Random31Not0Compute of a 31-bit random value <> 0, using the gsl_rng_taus2 generator
Random32Fast compute of some 32-bit random value, using the gsl_rng_taus2 generator
Random32Fast compute of bounded 32-bit random value, using the gsl_rng_taus2 generator
Random32SeedSeed the thread-specific gsl_rng_taus2 Random32 generator
Random64Fast compute of a 64-bit random value, using the gsl_rng_taus2 generator
RandomBytesFill a memory buffer with random bytes from the gsl_rng_taus2 generator
RandomDoubleFast compute of a 64-bit random floating point, using the gsl_rng_taus2 generator
RandomGuidCompute a random UUid value from the RandomBytes() generator and RFC 4122
RandomGuidCompute a random UUid value from the RandomBytes() generator and RFC 4122
RandomShort31Fill some string[31] with 7-bit ASCII random text
RawByteStringToVariantConvert a RawByteString content into a variant varString
RawByteStringToVariantConvert a raw binary buffer into a variant RawByteString varString
RawObjectsClearLow-level function calling FreeAndNil(o^) successively n times
RawUtf8ToVariantConvert an UTF-8 encoded string into a variant RawUtf8 varString
RawUtf8ToVariantConvert an UTF-8 encoded string into a variant RawUtf8 varString
RawUtf8ToVariantConvert an UTF-8 encoded text buffer into a variant RawUtf8 varString
RcuThread-safe move of a memory buffer using a simple Read-Copy-Update pattern
Rcu128Thread-safe move of a 128-bit value using a simple Read-Copy-Update pattern
Rcu32Thread-safe move of a 32-bit value using a simple Read-Copy-Update pattern
Rcu64Thread-safe move of a 64-bit value using a simple Read-Copy-Update pattern
RcuPtrThread-safe move of a pointer value using a simple Read-Copy-Update pattern
RdRand32Compute 32-bit random number generated by modern Intel CPU hardware
RdRand32XOR a memory buffer with some random generated by modern Intel CPU
RdtscReturns the 64-bit Intel Time Stamp Counter (TSC)
ReadBarrierThis function is an intrinsic in FPC
RleCompressSimple Run-Length-Encoding compression of a memory buffer
RleUnCompressSimple Run-Length-Encoding uncompression of a memory buffer
RleUnCompressPartialPartial Run-Length-Encoding uncompression of a memory buffer
SameValueCompare to floating point values, with IEEE 754 double precision
SameValueFloatCompare to floating point values, with IEEE 754 double precision
SetBitSet a particular bit into a bit array
SetBit64Set a particular bit into a 64-bit integer bits (max aIndex is 63)
SetBitPtrSet a particular bit into a bit array
SetInt64Get the 64-bit signed integer value stored in P^
SetQWordGet the 64-bit unsigned integer value stored in P^
SetQWordGet the 64-bit unsigned integer value stored in P^
SetVariantNullSame as Value := Null, but slightly faster
SetVariantUnRefSimpleValueSame as Dest := TVarData(Source) for simple values
ShortStringToAnsi7StringDirect conversion of an ANSI-7 ShortString into an AnsiString
ShortStringToAnsi7StringDirect conversion of an ANSI-7 ShortString into an AnsiString
SimpleRoundTo2DigitsNo banker rounding into two digits after the decimal point
SimpleRoundTo2DigitsCurr64Simple, no banker rounding of a Currency value, stored as Int64, to only 2 digits
SortDynArray128Compare two "array of THash128" 128-bit elements
SortDynArray256Compare two "array of THash256" 256-bit elements
SortDynArray512Compare two "array of THash512" 512-bit elements
SortDynArrayAnsiStringCompare two "array of AnsiString" elements, with case sensitivity
SortDynArrayBooleanCompare two "array of boolean" 8-bit elements
SortDynArrayByteCompare two "array of byte" 8-bit elements
SortDynArrayCardinalCompare two "array of cardinal" 32-bit elements
SortDynArrayDoubleCompare two "array of double" 64-bit elements
SortDynArrayExtendedCompare two "array of TSynExtended" 64/80-bit elements
SortDynArrayInt64Compare two "array of Int64" or "array of Currency" 64-bit elements
SortDynArrayIntegerCompare two "array of integer" 32-bit elements
SortDynArrayPointerCompare two "array of TObject/pointer" elements
SortDynArrayPUtf8CharCompare two "array of PUtf8Char/PAnsiChar" elements, with case sensitivity
SortDynArrayQWordCompare two "array of QWord" 64-bit elements
SortDynArrayShortintCompare two "array of shortint" 8-bit elements
SortDynArrayShortStringCompare two "array of shortstring" elements, with case sensitivity
SortDynArraySingleCompare two "array of single" 32-bit elements
SortDynArraySmallintCompare two "array of smallint" 16-bit elements
SortDynArrayStringCompare two "array of RTL string" elements, with case sensitivity
SortDynArrayUnicodeStringCompare two "array of WideString/UnicodeString" elements, with case sensitivity
SortDynArrayVariantCompare two "array of variant" elements, with case sensitivity
SortDynArrayVariantICompare two "array of variant" elements, with no case sensitivity
SortDynArrayWordCompare two "array of word" 16-bit elements
SortMatchFast search if a comparison function result (<0,0,>0) match an operator
SplitReturns the left part of a RawUtf8 string, according to SepStr separator
StrCntAddLow-level string reference counter process
StrCntDecFreeLow-level string reference counter unprocess
StrCompBuffer-overflow safe version of StrComp(), to be used with PUtf8Char/PAnsiChar
StrCompWOur fast version of StrComp(), to be used with PWideChar
StrInt32Internal fast integer val to text conversion
StrInt64Internal fast Int64 val to text conversion
StrLenSafeSimple version of StrLen(), but which will never read beyond the string
StrLenWOur fast version of StrLen(), to be used with PWideChar
StrUInt32Internal fast unsigned integer val to text conversion
StrUInt64Internal fast unsigned Int64 val to text conversion
SynLZcompress1Raw SynLZ compression algorithm
SynLZcompress1pasRaw SynLZ compression algorithm implemented in pascal
SynLZcompressdestlenGet maximum possible (worse) SynLZ compressed size
SynLZdecompress1Raw SynLZ decompression algorithm
SynLZdecompress1partialSynLZ decompression algorithm with memory boundaries check
SynLZdecompress1pasRaw SynLZ decompression algorithm implemented in pascal
SynLZdecompressdestlenGet exact uncompressed size from SynLZ-compressed buffer (to reserve memory, e.g.)
TInt64DynArrayFromQuick helper to initialize a dynamic array of 64-bit integers from 32-bit values
TIntegerDynArrayFromQuick helper to initialize a dynamic array of integer from some constants
TIntegerDynArrayFrom64Quick helper to initialize a dynamic array of integer from 64-bit integers
ToCardinalGet the unsigned 32-bit cardinal value stored in a RawUtf8 string
ToDoubleGet a 64-bit floating-point value stored in a RawUtf8 string
ToHumanHexConvert a binary into its human-friendly per-byte hexadecimal lowercase text
ToHumanHexReverseConvert a binary into its human-friendly hexadecimal in reverse order
ToInt64Get the signed 64-bit integer value stored in a RawUtf8 string
ToIntegerGet the signed 32-bit integer value stored in a RawUtf8 string
ToTextJust a wrapper around ClassToText() to avoid a string conversion
TQWordDynArrayFromQuick helper to initialize a dynamic array of 64-bit integers from 32-bit values
TrimFast dedicated RawUtf8 version of Trim()
TrimCopySingle-allocation (therefore faster) alternative to Trim(copy())
TrimSelfFast dedicated RawUtf8 version of s := Trim(s)
TrimUFast dedicated RawUtf8 version of Trim()
TruncTo2DigitsTruncate a currency value to only 2 digits
TruncTo2Digits64Truncate a Currency value, stored as Int64, to only 2 digits
TruncTo2DigitsCurr64Truncate a currency value, stored as Int64, to only 2 digits
TwoDigitsNo banker rounding into text, with two digits after the decimal point
UniqueRawUtf8Equivalence to @u[1] expression to ensure a RawUtf8 variable is unique
UnSetBitUnset/clear a particular bit into a bit array
UnSetBit64Unset/clear a particular bit into a 64-bit integer bits (max aIndex is 63)
UnSetBitPtrUnset/clear a particular bit into a bit array
Utf8ToInt64Get the signed 64-bit integer value stored in a RawUtf8 string
Utf8ToIntegerGet the signed 32-bit integer value stored in a RawUtf8 string
Utf8ToIntegerGet and check range of a signed 32-bit integer stored in a RawUtf8 string
VarClearAndSetTypeOverloaded function which can be properly inlined to clear a variant
VarDataFromVariantGet the root PVarData of a variant, redirecting any varByRef
VarDataIsEmptyOrNullSame as VarIsEmpty(PVariant(V)^) or VarIsNull(PVariant(V)^), but faster
VariantCompSimpleBasic default case-sensitive variant comparison function
VariantStringToUtf8Convert Variant string values into RawUtf8 encoded String
VariantStringToUtf8Convert a Variant varString value into RawUtf8 encoded String
VariantToBooleanConvert any numerical Variant into a boolean value
VariantToCurrencyConvert any numerical Variant into a fixed decimals floating point value
VariantToDoubleConvert any numerical Variant into a floating point value
VariantToDoubleDefConvert any numerical Variant into a floating point value
VariantToInt64Convert any numerical Variant into a 64-bit integer
VariantToInt64DefConvert any numerical Variant into a 64-bit integer
VariantToIntegerConvert any numerical Variant into a 32-bit integer
VariantToIntegerDefConvert any numerical Variant into an integer
VariantToRawByteStringConvert back a RawByteString from a variant
VarIsEmptyOrNullSame as VarIsEmpty(V) or VarIsNull(V), but faster
WordScanIndexFast search of an unsigned Word value position in a Word array
XorEntropyRetrieve 512-bit of entropy, from system time and current execution state
XorMemoryLogical XOR of two memory buffers into a third
XorMemoryLogical XOR of two memory buffers
xxHash32Perform very fast xxHash hashing in 32-bit mode
xxHash32MixupShuffle a 32-bit value using the last stage of xxHash32 algorithm
YearToPCharAdd the 4 digits of integer Y to P^ as '0000'..'9999'

1.5.1. AddGuid

function AddGuid(var guids: TGuidDynArray; const guid: TGuid; NoDuplicates: boolean = false): integer;

Append one TGuid item to a TGuid dynamic array
- returning the newly inserted index in guids[], or an existing index in guids[] if NoDuplicates is TRUE and TGuid already exists


1.5.2. AddHash128

function AddHash128(var Arr: THash128DynArray; const V: THash128; var Count: integer): PtrInt;

Add a 128-bit item in an array of such values


1.5.3. AddInt64

function AddInt64(var Values: TInt64DynArray; const Another: TInt64DynArray): PtrInt; overload;

Add a 64-bit integer array at the end of a dynamic array


1.5.4. AddInt64

function AddInt64(var Values: TInt64DynArray; var ValuesCount: integer; Value: Int64): PtrInt; overload;

Add a 64-bit integer value at the end of a dynamic array of integers


1.5.5. AddInt64

function AddInt64(var Values: TInt64DynArray; Value: Int64): PtrInt; overload;

Add a 64-bit integer value at the end of a dynamic array


1.5.6. AddInt64Once

function AddInt64Once(var Values: TInt64DynArray; Value: Int64): PtrInt;

If not already existing, add a 64-bit integer value to a dynamic array


1.5.7. AddInt64Sorted

procedure AddInt64Sorted(var Values: TInt64DynArray; Value: Int64);

If not already existing, add a 64-bit integer value to a sorted dynamic array


1.5.8. AddInteger

function AddInteger(var Values: TIntegerDynArray; Value: integer; NoDuplicates: boolean = false): boolean; overload;

Add an integer value at the end of a dynamic array of integers
- returns TRUE if Value was added successfully in Values[], in this case length(Values) will be increased


1.5.9. AddInteger

function AddInteger(var Values: TIntegerDynArray; var ValuesCount: integer; Value: integer; NoDuplicates: boolean): boolean; overload;

Add an integer value at the end of a dynamic array of integers
- this overloaded function will use a separate Count variable (faster), and would allow to search for duplicates
- returns TRUE if Value was added successfully in Values[], in this case ValuesCount will be increased, but length(Values) would stay fixed most of the time (since it stores the Values[] array capacity)


1.5.10. AddInteger

function AddInteger(var Values: TIntegerDynArray; const Another: TIntegerDynArray): PtrInt; overload;

Add an integer array at the end of a dynamic array of integer


1.5.11. AddInteger

procedure AddInteger(var Values: TIntegerDynArray; var ValuesCount: integer; Value: integer); overload;

Add an integer value at the end of a dynamic array of integers
- this overloaded function will use a separate Count variable (faster)
- it won't search for any existing duplicate


1.5.12. AddPtrUInt

function AddPtrUInt(var Values: TPtrUIntDynArray; var ValuesCount: integer; Value: PtrUInt): PtrInt;

Add a pointer-sized integer array at the end of a dynamic array


1.5.13. AddSortedInteger

function AddSortedInteger(var Values: TIntegerDynArray; Value: integer; CoValues: PIntegerDynArray = nil): PtrInt; overload;

Add an integer value in a sorted dynamic array of integers
- overloaded function which do not expect an external Count variable


1.5.14. AddSortedInteger

function AddSortedInteger(var Values: TIntegerDynArray; var ValuesCount: integer; Value: integer; CoValues: PIntegerDynArray = nil): PtrInt; overload;

Add an integer value in a sorted dynamic array of integers
- returns the index where the Value was added successfully in Values[]
- returns -(foundindex+1) i.e. <0 if the specified Value was already present
- if CoValues is set, its content will be moved to allow inserting a new value at CoValues[result] position


1.5.15. AddWord

function AddWord(var Values: TWordDynArray; var ValuesCount: integer; Value: Word): PtrInt;

Add a 16-bit integer value at the end of a dynamic array of integers


1.5.16. AndMemory

procedure AndMemory(Dest, Source: PByteArray; size: PtrInt);

Logical AND of two memory buffers
- will perform on all buffer bytes:

 Dest[i] := Dest[i] and Source[i];

1.5.17. Ansi7StringToShortString

procedure Ansi7StringToShortString(const source: RawUtf8; var result: ShortString);

Direct conversion of an ANSI-7 AnsiString into an ShortString
- can be used e.g. for names retrieved from RTTI


1.5.18. AppendShort

procedure AppendShort(const src: ShortString; var dest: ShortString);

Simple concatenation of a ShortString text into a shorstring


1.5.19. AppendShortAnsi7String

procedure AppendShortAnsi7String(const buf: RawByteString; var dest: ShortString);

Simple concatenation of an ANSI-7 AnsiString into a shorstring
- if Len is < 0, will use StrLen(buf)


1.5.20. AppendShortBuffer

procedure AppendShortBuffer(buf: PAnsiChar; len: integer; var dest: ShortString);

Simple concatenation of a #0 ending text into a shorstring
- if Len is < 0, will use StrLen(buf)


1.5.21. AppendShortByteHex

procedure AppendShortByteHex(value: byte; var dest: ShortString);

Simple concatenation of a byte as hexadecimal into a shorstring


1.5.22. AppendShortCardinal

procedure AppendShortCardinal(value: cardinal; var dest: ShortString);

Simple concatenation of a 32-bit unsigned integer as text into a shorstring


1.5.23. AppendShortChar

procedure AppendShortChar(chr: AnsiChar; var dest: ShortString);

Simple concatenation of a character into a shorstring


1.5.24. AppendShortInt64

procedure AppendShortInt64(value: Int64; var dest: ShortString);

Simple concatenation of a 64-bit integer as text into a shorstring


1.5.25. BitsToBytes

function BitsToBytes(bits: byte): byte;

Compute how many bytes are needed to store a given number of bits
- e.g. 0 returns 0, 1..8 returns 1, 9..16 returns 2, and so on


1.5.26. BSRdword

function BSRdword(c: cardinal): cardinal;

Return the position of the leftmost set bit in a 32-bit value
- returns 255 if c equals 0
- this function is an intrinsic on FPC


1.5.27. BSRqword

function BSRqword(const q: Qword): cardinal;

Return the position of the leftmost set bit in a 64-bit value
- returns 255 if q equals 0
- this function is an intrinsic on FPC


1.5.28. bswap32

function bswap32(a: cardinal): cardinal;

Convert the endianness of a given unsigned 32-bit integer into BigEndian


1.5.29. bswap64

function bswap64(const a: QWord): QWord;

Convert the endianness of a given unsigned 64-bit integer into BigEndian


1.5.30. bswap64array

procedure bswap64array(a, b: PQWordArray; n: PtrInt);

Convert the endianness of an array of unsigned 64-bit integer into BigEndian
- n is required to be > 0
- warning: on x86, a should be <> b


1.5.31. BufferLineLength

function BufferLineLength(Text, TextEnd: PUtf8Char): PtrInt;

Compute the line length from a size-delimited source array of chars
- will use fast SSE2 assembly on x86-64 CPU
- is likely to read some bytes after the TextEnd buffer, so GetLineSize() from mormot.core.text may be preferred, e.g. on memory mapped files
- expects Text and TextEnd to be not nil - see GetLineSize() instead


1.5.32. ByteScanIndex

function ByteScanIndex(P: PByteArray; Count: PtrInt; Value: byte): PtrInt;

Fast search of an unsigned byte value position in a byte array
- Count is the number of byte entries in P^
- return index of P^[index]=Value, -1 if Value was not found
- is implemented with SSE2 asm on i386 and x86_64


1.5.33. ClassNameShort

function ClassNameShort(Instance: TObject): PShortString; overload;

Just a wrapper around vmtClassName to avoid a string conversion


1.5.34. ClassNameShort

function ClassNameShort(C: TClass): PShortString; overload;

Just a wrapper around vmtClassName to avoid a string conversion


1.5.35. ClassToText

procedure ClassToText(C: TClass; var result: RawUtf8);

Just a wrapper around vmtClassName to avoid a string conversion


1.5.36. ClearVariantForString

procedure ClearVariantForString(var Value: variant);

Internal efficient wrapper of VarClear() + set VType=varString and VAny=nil
- used e.g. by RawUtf8ToVariant() functions
- could also be used as a faster alternative to Value := ''


1.5.37. CompareBuf

function CompareBuf(const P1, P2: RawByteString): integer; overload;

Overload wrapper to SortDynArrayRawByteString(P1, P2)
- won't involve any code page - so may be safer e.g. on FPC


1.5.38. CompareBuf

function CompareBuf(const P1: RawByteString; P2: pointer; P2Len: PtrInt): integer; overload;

Overload wrapper of MemCmp() to compare a RawByteString vs a memory buffer
- will first check length(P1)=P2Len then call MemCmp()


1.5.39. CompareCardinal

function CompareCardinal(const A, B: cardinal): integer;

A comparison function for sorting 32-bit unsigned integer values


1.5.40. CompareFloat

function CompareFloat(const A, B: double): integer;

A comparison function for sorting IEEE 754 double precision values


1.5.41. CompareInt64

function CompareInt64(const A, B: Int64): integer;

A comparison function for sorting 64-bit signed integer values


1.5.42. CompareInteger

function CompareInteger(const A, B: integer): integer;

A comparison function for sorting 32-bit signed integer values


1.5.43. CompareMem

function CompareMem(P1, P2: pointer; Length: PtrInt): boolean;

Our fast version of CompareMem()
- tuned asm for x86, call MemCmpSse2 for x64, or fallback to tuned pascal


1.5.44. CompareMemSmall

function CompareMemSmall(P1, P2: pointer; Length: PtrInt): boolean;

A CompareMem()-like function designed for small (a few bytes) content
- to be efficiently inlined in processing code


1.5.45. ComparePointer

function ComparePointer(const A, B: pointer): integer;

A comparison function for sorting 32/64-bit pointers as unsigned values


1.5.46. ComparePtrInt

function ComparePtrInt(const A, B: PtrInt): integer;

A comparison function for sorting 32/64-bit signed integer values


1.5.47. CompareQWord

function CompareQWord(const A, B: QWord): integer;

A comparison function for sorting 64-bit unsigned integer values
- note that QWord(A)>QWord(B) is wrong on older versions of Delphi, so you should better use this function or SortDynArrayQWord() to properly compare two QWord values over CPUX86 on Delphi 7-2007


1.5.48. CompressSynLZ

function CompressSynLZ(var Data: RawByteString; Compress: boolean): RawUtf8;

Compress a data content using the SynLZ algorithm
- as expected by THttpSocket.RegisterCompress
- will return 'synlz' as ACCEPT-ENCODING: header parameter
- will store a hash of both compressed and uncompressed stream: if the data is corrupted during transmission, will instantly return ''


1.5.49. CompressSynLZGetHash32

function CompressSynLZGetHash32(const Data: RawByteString): cardinal;

Return the Hash32() 32-bit CRC of CompressSynLZ() uncompressed data
- will first check the CRC of the supplied compressed Data
- returns 0 if the CRC of the compressed Data is not correct


1.5.50. crc128c

procedure crc128c(buf: PAnsiChar; len: cardinal; out crc: THash128);

Compute a 128-bit checksum on the supplied buffer, cascading two crc32c
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- will combine two crc32c() calls into a single TAesBlock result
- by design, such combined hashes cannot be cascaded


1.5.51. crc16

function crc16(Data: PAnsiChar; Len: integer): cardinal;

Compute CRC16-CCITT checkum on the supplied buffer
- i.e. 16-bit CRC-CCITT, with polynomial x^16 + x^12 + x^5 + 1 ($1021) and $ffff as initial value
- this version is not optimized for speed, but for correctness


1.5.52. crc256c

procedure crc256c(buf: PAnsiChar; len: cardinal; out crc: THash256);

Compute a 256-bit checksum on the supplied buffer using crc32c
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- will combine two crc32c() calls into a single THash256 result
- by design, such combined hashes cannot be cascaded


1.5.53. crc32c128

procedure crc32c128(hash: PHash128; buf: PAnsiChar; len: cardinal);

Compute a 128-bit CRC of any binary buffers
- combine crcblocks() with 4 parallel crc32c() for 1..15 trailing bytes


1.5.54. crc32cBy4fast

function crc32cBy4fast(crc, value: cardinal): cardinal;

Pure pascal function implementing crc32cBy4()


1.5.55. crc32cfast

function crc32cfast(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;

Compute CRC32C checksum on the supplied buffer on processor-neutral code
- result is compatible with SSE 4.2 based hardware accelerated instruction
- will use fast x86/x64 asm or efficient pure pascal implementation on ARM
- result is not compatible with zlib's crc32() - not the same polynom
- crc32cfast() is 1.7 GB/s, crc32csse42() is 4.3 GB/s
- you should use crc32c() function instead of crc32cfast() or crc32csse42()


1.5.56. crc32cHash

function crc32cHash(const s: RawByteString): cardinal; overload;

Compute a 32-bit hash of any string using the CRC32C checksum
- the returned hash value will be stable on all platforms, and use HW opcodes if available on the current CPU


1.5.57. crc32cHash

function crc32cHash(const b: TBytes): cardinal; overload;

Compute a 32-bit hash of any array of bytes using the CRC32C checksum
- the returned hash value will be stable on all platforms, and use HW opcodes if available on the current CPU


1.5.58. crc32cinlined

function crc32cinlined(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;

Compute CRC32C checksum on the supplied buffer using inlined code
- if the compiler supports inlining, will compute a slow but safe crc32c checksum of the binary buffer, without calling the main crc32c() function
- may be used e.g. to identify patched executable at runtime, for a licensing protection system, or if you don't want to pollute the CPU L1 cache with crc32cfast() bigger lookup tables


1.5.59. crc32csse42

function crc32csse42(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;

Defined here for mormot.test.base only
- use instead global crc32c() variable


1.5.60. crc32ctwice

function crc32ctwice(seed: QWord; buf: PAnsiChar; len: cardinal): QWord;

Expand a CRC32C checksum on the supplied buffer for 64-bit hashing
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- is the default implementation of DefaultHasher64


1.5.61. crc32fast

function crc32fast(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;

Compute CRC32 checksum on the supplied buffer on processor-neutral code
- result is compatible with zlib's crc32() but not with crc32c/crc32cfast()


1.5.62. crc63c

function crc63c(buf: PAnsiChar; len: cardinal): Int64;

Compute CRC63C checksum on the supplied buffer, cascading two crc32c
- similar to crc64c, but with 63-bit, so no negative value: may be used safely e.g. as mORMot's TID source
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- will combine two crc32c() calls into an unsigned 63-bit Int64 result
- by design, such combined hashes cannot be cascaded


1.5.63. crc64c

function crc64c(buf: PAnsiChar; len: cardinal): Int64;

Compute CRC64C checksum on the supplied buffer, cascading two crc32c
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- will combine two crc32c() calls into a single Int64 result
- by design, such combined hashes cannot be cascaded


1.5.64. crcblockfast

procedure crcblockfast(crc128, data128: PBlock128);

Computation of our 128-bit CRC of a 128-bit binary buffer without SSE4.2
- to be used for regression tests only: crcblock will use the fastest implementation available on the current CPU (e.g. with SSE 4.2 or ARMv8)


1.5.65. crcblocksfast

procedure crcblocksfast(crc128, data128: PBlock128; count: integer);

Compute a proprietary 128-bit CRC of 128-bit binary buffers
- to be used for regression tests only: crcblocks will use the fastest implementation available on the current CPU (e.g. with SSE 4.2 or ARMv8)


1.5.66. CurrencyToDouble

procedure CurrencyToDouble(const c: currency; out d: double); overload;

Convert a currency value into a double
- using PInt64() division by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.67. CurrencyToDouble

procedure CurrencyToDouble(c: PCurrency; out d: double); overload;

Convert a currency value pointer into a double
- using PInt64() division by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.68. CurrencyToDouble

function CurrencyToDouble(c: PCurrency): double; overload;

Convert a currency value pointer into a double
- using PInt64() division by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.69. CurrencyToInt64

procedure CurrencyToInt64(c: PCurrency; var i: Int64); overload;

Convert a currency value into a Int64
- using PInt64() division by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.70. CurrencyToVariant

procedure CurrencyToVariant(const c: currency; var v: variant);

Fill a variant value from a currency value
- as compatible with VariantToCurrency/VariantToDouble
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.71. DACntAdd

procedure DACntAdd(var refcnt: TDACnt; increment: TDACnt);

Low-level dynarray reference counter process


1.5.72. DACntDecFree

function DACntDecFree(var refcnt: TDACnt): boolean;

Low-level dynarray reference counter unprocess
- caller should have tested that refcnt>=0


1.5.73. DateTimeToIsoString

function DateTimeToIsoString(dt: TDateTime): string;

Use the RTL to return a date/time as ISO-8601 text
- slow function, here to avoid linking mormot.core.datetime


1.5.74. DefaultHash

function DefaultHash(const b: TBytes): cardinal; overload;

Compute a 32-bit hash of any array of bytes using DefaultHasher()
- so the hash value may change on another computer or after program restart


1.5.75. DefaultHash

function DefaultHash(const s: RawByteString): cardinal; overload;

Compute a 32-bit hash of any string using DefaultHasher()
- so the hash value may change on another computer or after program restart


1.5.76. DeleteInt64

procedure DeleteInt64(var Values: TInt64DynArray; var ValuesCount: integer; Index: PtrInt); overload;

Delete any 64-bit integer in Values[]


1.5.77. DeleteInt64

procedure DeleteInt64(var Values: TInt64DynArray; Index: PtrInt); overload;

Delete any 64-bit integer in Values[]


1.5.78. DeleteInteger

procedure DeleteInteger(var Values: TIntegerDynArray; var ValuesCount: integer; Index: PtrInt); overload;

Delete any 32-bit integer in Values[]


1.5.79. DeleteInteger

procedure DeleteInteger(var Values: TIntegerDynArray; Index: PtrInt); overload;

Delete any 32-bit integer in Values[]


1.5.80. DeleteWord

procedure DeleteWord(var Values: TWordDynArray; Index: PtrInt);

Delete any 16-bit integer in Values[]


1.5.81. Div100

procedure Div100(Y: cardinal; var res: TDiv100Rec);

Simple wrapper to efficiently compute both division and modulo per 100
- compute result.D = Y div 100 and result.M = Y mod 100
- under FPC, will use fast multiplication by reciprocal so can be inlined
- under Delphi, we use our own optimized asm version (which can't be inlined)


1.5.82. DoubleToCurrency

procedure DoubleToCurrency(const d: double; c: PCurrency); overload;

Convert a double value into a currency
- using truncated multiplication by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.83. DoubleToCurrency

procedure DoubleToCurrency(const d: double; out c: currency); overload;

Convert a double value into a currency
- using truncated multiplication by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.84. DoubleToCurrency

function DoubleToCurrency(const d: double): currency; overload;

Convert a double value into a currency
- using truncated multiplication by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.85. DynArrayFakeLength

procedure DynArrayFakeLength(arr: pointer; len: TDALen);

Like SetLength() but without any memory resize - WARNING: len should be > 0


1.5.86. DynArrayHashTableAdjust

procedure DynArrayHashTableAdjust(P: PIntegerArray; deleted: integer; count: PtrInt);

Internal hash table adjustment as called from TDynArrayHasher.HashDelete
- decrement any integer greater or equal to a deleted value
- brute force O(n) indexes fix after deletion (much faster than full ReHash)
- we offer very optimized SSE2 and AVX2 versions on x86_64 - therefore is defined in this unit to put this asm code in mormot.core.base.asmx64.inc


1.5.87. DynArrayHashTableAdjust16

procedure DynArrayHashTableAdjust16(P: PWordArray; deleted: cardinal; count: PtrInt);

DynArrayHashTableAdjust() version for 16-bit HashTable[] - SSE2 asm on x86_64


1.5.88. EnsureRawUtf8

procedure EnsureRawUtf8(var s: RawByteString); overload;

Ensure the supplied variable will have a CP_UTF8 - making it unique if needed


1.5.89. EnsureRawUtf8

procedure EnsureRawUtf8(var s: RawUtf8); overload;

Ensure the supplied variable will have a CP_UTF8 - making it unique if needed


1.5.90. EqualBuf

function EqualBuf(const P1, P2: RawByteString): boolean; overload;

Overload wrapper to SortDynArrayRawByteString(P1, P2) = 0
- won't involve any code page - so may be safer e.g. on FPC


1.5.91. EventEquals

function EventEquals(const eventA, eventB): boolean;

Compare two TMethod instances


1.5.92. Exchg

procedure Exchg(P1, P2: PAnsiChar; count: PtrInt);

Low-level inlined function for exchanging two memory buffers
- used e.g. during sorting process


1.5.93. ExchgPointer

procedure ExchgPointer(n1, n2: PPointer);

Low-level inlined function for exchanging two pointers
- used e.g. during sorting process


1.5.94. ExchgPointers

procedure ExchgPointers(n1, n2: PPointer; count: PtrInt);

Low-level inlined function for exchanging two sets of pointers
- used e.g. during sorting process


1.5.95. ExchgVariant

procedure ExchgVariant(v1, v2: PPtrIntArray);

Low-level inlined function for exchanging two variants
- used e.g. during sorting process


1.5.96. FakeCodePage

procedure FakeCodePage(var s: RawByteString; cp: cardinal);

Internal function which could be used instead of SetCodePage() if RefCnt = 1
- do nothing if HASCODEPAGE is not defined, e.g. on Delphi 7-2007
- warning: s should NOT be read-only (i.e. assigned from a constant), but a just-allocated string with RefCnt <> -1


1.5.97. FakeLength

procedure FakeLength(var s: RawUtf8; endChar: PUtf8Char); overload;

Internal function which could be used instead of SetLength() if RefCnt = 1


1.5.98. FakeLength

procedure FakeLength(var s: RawUtf8; len: PtrInt); overload;

Internal function which could be used instead of SetLength() if RefCnt = 1


1.5.99. FakeLength

procedure FakeLength(var s: RawByteString; len: PtrInt); overload;

Internal function which could be used instead of SetLength() if RefCnt = 1


1.5.100. FakeSetLength

procedure FakeSetLength(var s: RawUtf8; len: PtrInt); overload;

Internal function which could be used instead of SetLength() if RefCnt = 1
- FakeLength() don't handle len = 0, whereas this function will


1.5.101. FakeSetLength

procedure FakeSetLength(var s: RawByteString; len: PtrInt); overload;

Internal function which could be used instead of SetLength() if RefCnt = 1
- FakeLength() don't handle len = 0, whereas this function will


1.5.102. FastAssignNew

procedure FastAssignNew(var d; s: pointer = nil);

Assign any constant or already ref-counted AnsiString/RawUtf8
- by default, called with s = nil, is an equivalence to Finalize(d) or d := ''
- is also called by FastSetString/FastSetStringCP to setup its allocated value
- faster especially under FPC


1.5.103. FastAssignNewNotVoid

procedure FastAssignNewNotVoid(var d; s: pointer); overload;

Internal function to assign any constant or ref-counted AnsiString/RawUtf8
- caller should have tested that pointer(d) <> nil


1.5.104. FastAssignUtf8

procedure FastAssignUtf8(var dest: RawUtf8; var src: RawByteString);

Internal function which assign src to dest, force CP_UTF8 and set src to ''
- warning: calls FakeCodePage(CP_UTF8) so requires src to have a RefCnt of 1


1.5.105. FastFindInt64Sorted

function FastFindInt64Sorted(P: PInt64Array; R: PtrInt; const Value: Int64): PtrInt; overload;

Fast O(log(n)) binary search of a 64-bit signed integer value in a sorted array
- R is the last index of available integer entries in P^ (i.e. Count-1)
- return index of P^[result]=Value
- return -1 if Value was not found
- use branchless asm on x86_64


1.5.106. FastFindIntegerSorted

function FastFindIntegerSorted(const Values: TIntegerDynArray; Value: integer): PtrInt; overload;

Fast O(log(n)) binary search of an integer value in a sorted integer array
- return index of Values[result]=Value
- return -1 if Value was not found


1.5.107. FastFindIntegerSorted

function FastFindIntegerSorted(P: PIntegerArray; R: PtrInt; Value: integer): PtrInt; overload;

Fast O(log(n)) binary search of an integer value in a sorted integer array
- R is the last index of available integer entries in P^ (i.e. Count-1)
- return index of P^[result]=Value
- return -1 if Value was not found
- use branchless asm on x86_64


1.5.108. FastFindPointerSorted

function FastFindPointerSorted(P: PPointerArray; R: PtrInt; Value: pointer): PtrInt; overload;

Fast O(log(n)) binary search of a pointer value in a sorted array


1.5.109. FastFindPtrIntSorted

function FastFindPtrIntSorted(P: PPtrIntArray; R: PtrInt; Value: PtrInt): PtrInt; overload;

Fast O(log(n)) binary search of a PtrInt value in a sorted array


1.5.110. FastFindQWordSorted

function FastFindQWordSorted(P: PQWordArray; R: PtrInt; const Value: QWord): PtrInt; overload;

Fast O(log(n)) binary search of a 64-bit unsigned integer value in a sorted array
- R is the last index of available integer entries in P^ (i.e. Count-1)
- return index of P^[result]=Value
- return -1 if Value was not found
- QWord comparison are implemented correctly under FPC or Delphi 2009+ - older compilers will fast and exact SortDynArrayQWord()


1.5.111. FastFindWordSorted

function FastFindWordSorted(P: PWordArray; R: PtrInt; Value: Word): PtrInt;

Fast O(log(n)) binary search of a 16-bit unsigned integer value in a sorted array
- use branchless asm on x86_64


1.5.112. FastLocateIntegerSorted

function FastLocateIntegerSorted(P: PIntegerArray; R: PtrInt; Value: integer): PtrInt;

Retrieve the index where to insert an integer value in a sorted integer array
- R is the last index of available integer entries in P^ (i.e. Count-1)
- returns -(foundindex+1) i.e. <0 if the specified Value was found


1.5.113. FastLocateWordSorted

function FastLocateWordSorted(P: PWordArray; R: integer; Value: word): PtrInt;

Retrieve the index where to insert a word value in a sorted word array
- R is the last index of available integer entries in P^ (i.e. Count-1)
- returns -(foundindex+1) i.e. <0 if the specified Value was found


1.5.114. FastNewRawByteString

procedure FastNewRawByteString(var s: RawByteString; len: PtrInt);

Equivalence to SetString(s,nil,len) function to allocate a new RawByteString
- faster especially under FPC


1.5.115. FastNewString

function FastNewString(len, codepage: PtrInt): PAnsiChar;

Internal function used by FastSetString/FastSetStringCP


1.5.116. FastSearchIntegerSorted

function FastSearchIntegerSorted(P: PIntegerArray; R: PtrInt; Value: integer): PtrInt;

Retrieve the matching index or where to insert an integer value


1.5.117. FastSetRawByteString

procedure FastSetRawByteString(var s: RawByteString; p: pointer; len: PtrInt);

Equivalence to SetString(s,pansichar,len) function but from a raw pointer
- so works with both PAnsiChar and PUtf8Char input buffer (or even PByteArray)
- faster especially under FPC


1.5.118. FastSetString

procedure FastSetString(var s: RawUtf8; len: PtrInt); overload;

Faster equivalence to SetString(s,nil,len) function


1.5.119. FastSetString

procedure FastSetString(var s: RawUtf8; p: pointer; len: PtrInt); overload;

Equivalence to SetString(s,pansichar,len) function but from a raw pointer
- so works with both PAnsiChar and PUtf8Char input buffer (or even PByteArray)
- faster especially under FPC


1.5.120. FastSetStringCP

procedure FastSetStringCP(var s; p: pointer; len, codepage: PtrInt);

Equivalence to SetString(s,pansichar,len) function with a specific code page
- faster especially under FPC


1.5.121. FillAnsiStringFromRandom

procedure FillAnsiStringFromRandom(dest: PByteArray; size: PtrUInt);

Internal function used e.g. by TLecuyer.FillShort/FillShort31


1.5.122. FillcharFast

procedure FillcharFast(var dst; cnt: PtrInt; value: byte);

Our fast version of FillChar() on Intel/AMD
- on Intel i386/x86_64, will use fast SSE2/AVX instructions (if available)
- on non-Intel CPUs, it will fallback to the default RTL FillChar()
- note: Delphi RTL is far from efficient: on i386 the FPU is slower/unsafe, and on x86_64, ERMS is wrongly used even for small blocks
- on ARM/AARCH64 POSIX, mormot.core.os would redirect to optimized libc


1.5.123. FillIncreasing

procedure FillIncreasing(Values: PIntegerArray; StartValue: integer; Count: PtrUInt);

Fill some values with i,i+1,i+2...i+Count-1


1.5.124. FillRandom

procedure FillRandom(Dest: PCardinal; CardinalCount: integer);

Fill some 32-bit memory buffer with values from the gsl_rng_taus2 generator
- the destination buffer is expected to be allocated as 32-bit items


1.5.125. FillZero

procedure FillZero(var dest; count: PtrInt); overload;

Fill all bytes of a memory buffer with zero
- just redirect to FillCharFast(..,...,0)


1.5.126. FillZero

procedure FillZero(var Values: TInt64DynArray); overload;

Fill all entries of a supplied array of 64-bit integers with 0


1.5.127. FillZero

procedure FillZero(var Values: TIntegerDynArray); overload;

Fill all entries of a supplied array of 32-bit integers with 0


1.5.128. FillZero

procedure FillZero(out dig: THash384); overload;

Fill all 32 bytes of this 384-bit buffer with zero
- may be used to cleanup stack-allocated content

 ... finally FillZero(digest); end;

1.5.129. FillZero

procedure FillZero(out dig: THash128); overload;

Fill all 16 bytes of this 128-bit buffer with zero
- may be used to cleanup stack-allocated content

 ... finally FillZero(digest); end;

1.5.130. FillZero

procedure FillZero(out dig: THash256); overload;

Fill all 32 bytes of this 256-bit buffer with zero
- may be used to cleanup stack-allocated content

 ... finally FillZero(digest); end;

1.5.131. FillZero

procedure FillZero(out dig: THash512); overload;

Fill all 64 bytes of this 512-bit buffer with zero
- may be used to cleanup stack-allocated content

 ... finally FillZero(digest); end;

1.5.132. FillZero

procedure FillZero(out dig: THash160); overload;

Fill all 20 bytes of this 160-bit buffer with zero
- may be used to cleanup stack-allocated content

 ... finally FillZero(digest); end;

1.5.133. FillZero

procedure FillZero(var result: TGuid); overload;

Fill a TGuid with 0


1.5.134. FillZeroSmall

procedure FillZeroSmall(P: pointer; Length: PtrInt);

Fill first bytes of a memory buffer with zero
- Length is expected to be not 0, typically in 1..8 range
- when inlined, is slightly more efficient than regular FillZero/FillCharFast


1.5.135. FindNonVoidRawUtf8

function FindNonVoidRawUtf8(n: PPointerArray; name: pointer; len: TStrLen; count: PtrInt): PtrInt;

Raw internal method as published by FindNonVoid[false]


1.5.136. FindNonVoidRawUtf8I

function FindNonVoidRawUtf8I(n: PPointerArray; name: pointer; len: TStrLen; count: PtrInt): PtrInt;

Raw internal method as published by FindNonVoid[true]


1.5.137. FindPropName

function FindPropName(const Names: array of RawUtf8; const Name: RawUtf8): integer; overload;

Return the index of Value in Values[], -1 if not found
- here name search would use fast IdemPropNameU() function


1.5.138. FindPropName

function FindPropName(Values: PRawUtf8Array; const Value: RawUtf8; ValuesCount: PtrInt): PtrInt; overload;

Return the case-insensitive ASCII 7-bit index of Value in non-void Values[]
- typical use with a TRawUtf8DynArray is like this:

 index := FindPropName(pointer(aDynArray), aValue, length(aDynArray));

- by design, this function expects Values[] to not contain any void ''


1.5.139. fnv32

function fnv32(crc: cardinal; buf: PAnsiChar; len: PtrInt): cardinal;

Simple FNV-1a hashing function
- when run over our regression suite, is similar to crc32c() about collisions, and 4 times better than kr32(), but also slower than the others
- fnv32() is 715.5 MB/s - kr32() 898.8 MB/s
- this hash function should not be usefull, unless you need several hashing algorithms at once (e.g. if crc32c with diverse seeds is not enough)


1.5.140. FreeAndNilSafe

procedure FreeAndNilSafe(var aObj);

Same as FreeAndNil() but catching and ignoring any exception
- only difference is that aObj is set to nil AFTER being destroyed


1.5.141. FromI32

function FromI32(const Values: array of integer): TIntegerDynArray;

Initializes a dynamic array from a set of 32-bit integer signed values


1.5.142. FromI64

function FromI64(const Values: array of Int64): TInt64DynArray;

Initializes a dynamic array from a set of 64-bit integer signed values


1.5.143. FromU32

function FromU32(const Values: array of cardinal): TCardinalDynArray;

Initializes a dynamic array from a set of 32-bit integer unsigned values


1.5.144. FromU64

function FromU64(const Values: array of QWord): TQWordDynArray;

Initializes a dynamic array from a set of 64-bit integer unsigned values


1.5.145. gcd

function gcd(a, b: PtrUInt): PtrUInt;

Compute GCD of two integers using modulo-based Euclidean algorithm


1.5.146. GetAllBits

function GetAllBits(Bits, BitCount: cardinal): boolean;

Returns TRUE if all BitCount bits are set in the input 32-bit cardinal


1.5.147. GetBit

function GetBit(const Bits; aIndex: PtrInt): boolean;

Retrieve a particular bit status from a bit array
- this function can't be inlined, whereas GetBitPtr() function can


1.5.148. GetBit64

function GetBit64(const Bits: Int64; aIndex: PtrInt): boolean;

Retrieve a particular bit status from a 64-bit integer bits (max aIndex is 63)


1.5.149. GetBitPtr

function GetBitPtr(Bits: pointer; aIndex: PtrInt): boolean;

Retrieve a particular bit status from a bit array
- GetBit() can't be inlined, whereas this pointer-oriented function can


1.5.150. GetBitsCount

function GetBitsCount(const Bits; Count: PtrInt): PtrInt;

Compute the number of bits set in a bit array
- Count is the number of BITS to check, not the byte size
- will use fast SSE4.2 popcnt instruction if available on the CPU


1.5.151. GetBitsCountPas

function GetBitsCountPas(value: PtrInt): PtrInt;

Pure pascal version of GetBitsCountPtrInt()
- defined just for regression tests - call GetBitsCountPtrInt() instead
- has optimized asm on x86_64 and i386


1.5.152. GetBitsCountSSE42

function GetBitsCountSSE42(value: PtrInt): PtrInt;

Defined here for mormot.test.base only


1.5.153. GetBoolean

function GetBoolean(P: PUtf8Char): boolean; overload;

Get a boolean value stored as 'true'/'false' text in P^
- would also recognize any non '0' integer as true, or false if P = nil
- see relaxed GetInt64Bool() to recognize e.g. 'TRUE' or 'yes'/'YES'


1.5.154. GetBoolean

function GetBoolean(const value: RawUtf8): boolean; overload;

Get a boolean value stored as 'true'/'false' text in input variable
- would also recognize any non '0' integer as true, or false if P is ''


1.5.155. GetCardinal

function GetCardinal(P: PUtf8Char): PtrUInt; overload;

Get the unsigned 32-bit integer value stored in P^
- we use the PtrUInt result type, even if expected to be 32-bit, to use native CPU register size (don't want any 32-bit overflow here)


1.5.156. GetCardinal

function GetCardinal(P, PEnd: PUtf8Char): PtrUInt; overload;

Get the unsigned 32-bit integer value stored in P^
- we use the PtrUInt result type, even if expected to be 32-bit, to use native CPU register size (don't want any 32-bit overflow here)


1.5.157. GetCardinalDef

function GetCardinalDef(P: PUtf8Char; Default: PtrUInt): PtrUInt;

Get the unsigned 32-bit integer value stored in P^
- if P if nil or not start with a valid numerical value, returns Default


1.5.158. GetCardinalW

function GetCardinalW(P: PWideChar): PtrUInt;

Get the unsigned 32-bit integer value stored as Unicode string in P^


1.5.159. GetClassParent

function GetClassParent(C: TClass): TClass;

Just a wrapper around vmtParent to avoid a function call
- slightly faster than TClass.ClassParent thanks to proper inlining


1.5.160. GetExtended

function GetExtended(P: PUtf8Char): TSynExtended; overload;

Get the extended floating point value stored in P^
- this overloaded version returns 0 as a result if the content of P is invalid


1.5.161. GetExtended

function GetExtended(P: PUtf8Char; out err: integer): TSynExtended; overload;

Get the extended floating point value stored in P^
- set the err content to the index of any faulty character, 0 if conversion was successful (same as the standard val function)
- this optimized function is consistent on all platforms/compilers and return the decoded value even if err is not 0 (e.g. if P^ is not #0 ended)


1.5.162. GetInt64

function GetInt64(P: PUtf8Char; var err: integer): Int64; overload;

Get the 64-bit signed integer value stored in P^
- set the err content to the index of any faulty character, 0 if conversion was successful (same as the standard val function)


1.5.163. GetInt64

function GetInt64(P: PUtf8Char): Int64; overload;

Get the 64-bit integer value stored in P^


1.5.164. GetInt64Bool

function GetInt64Bool(P: PUtf8Char; out V: Int64): boolean;

Get the 64-bit integer value from P^, recognizing true/false/yes/no input
- return true on correct parsing, false if P is no number or boolean


1.5.165. GetInt64Def

function GetInt64Def(P: PUtf8Char; const Default: Int64): Int64;

Get the 64-bit integer value stored in P^
- if P if nil or not start with a valid numerical value, returns Default


1.5.166. GetInteger

function GetInteger(P: PUtf8Char): PtrInt; overload;

Get the signed 32-bit integer value stored in P^
- we use the PtrInt result type, even if expected to be 32-bit, to use native CPU register size (don't want any 32-bit overflow here)
- will end parsing when P^ does not contain any number (e.g. it reaches any ending #0 char)


1.5.167. GetInteger

function GetInteger(P: PUtf8Char; var err: integer): PtrInt; overload;

Get the signed 32-bit integer value stored in P^
- this version return 0 in err if no error occurred, and 1 if an invalid character was found, not its exact index as for the val() function


1.5.168. GetInteger

function GetInteger(P, PEnd: PUtf8Char): PtrInt; overload;

Get the signed 32-bit integer value stored in P^..PEnd^
- will end parsing when P^ does not contain any number (e.g. it reaches any ending #0 char), or when P reached PEnd (avoiding any buffer overflow)


1.5.169. GetIntegerDef

function GetIntegerDef(P: PUtf8Char; Default: PtrInt): PtrInt;

Get the signed 32-bit integer value stored in P^
- if P if nil or not start with a valid numerical value, returns Default


1.5.170. GetMemAligned

procedure GetMemAligned(var holder: RawByteString; fillwith: pointer; len: PtrUInt; out aligned: pointer; alignment: PtrUInt = 16);

Initialize a RawByteString, ensuring returned "aligned" pointer is 16-bytes aligned
- to be used e.g. for proper SIMD process
- you can specify an alternate alignment, but it should be a power of two


1.5.171. GetQWord

function GetQWord(P: PUtf8Char; var err: integer): QWord;

Get the 64-bit unsigned integer value stored in P^
- set the err content to the index of any faulty character, 0 if conversion was successful (same as the standard val function)


1.5.172. GetTrue

function GetTrue(P: PUtf8Char): integer;

Return 1 if 'TRUE' or 'YES', or 0 otherwise


1.5.173. GotoNextControlChar

function GotoNextControlChar(source: PUtf8Char): PUtf8Char;

Fast go to the first char <= #13
- source is expected to be not nil


1.5.174. GotoNextLine

function GotoNextLine(source: PUtf8Char): PUtf8Char;

Fast go to next text line, ended by #13 or #13#10
- source is expected to be not nil
- returns the beginning of next line, or nil if source^=#0 was reached


1.5.175. Hash128Index

function Hash128Index(P: PHash128Rec; Count: integer; h: PHash128Rec): integer;

Fast O(n) search of a 128-bit item in an array of such values


1.5.176. Hash128To64

function Hash128To64(const b: THash128): QWord;

Combine/reduce a 128-bit hash into a 64-bit hash
- e.g. from non cryptographic 128-bit hashers with linked lower/higher 64-bit


1.5.177. Hash256Index

function Hash256Index(P: PHash256Rec; Count: integer; h: PHash256Rec): integer;

Fast O(n) search of a 256-bit item in an array of such values


1.5.178. Hash32

function Hash32(Data: PCardinalArray; Len: integer): cardinal; overload;

Our custom efficient 32-bit hash/checksum function
- a Fletcher-like checksum algorithm, not a hash function: has less colisions than Adler32 for short strings, but more than xxhash32 or crc32/crc32c
- written in simple plain pascal, with no L1 CPU cache pollution, but we also provide optimized x86/x64 assembly versions, since the algorithm is used heavily e.g. for TDynArray binary serialization, TRestStorageInMemory binary persistence, or CompressSynLZ/StreamSynLZ/FileSynLZ
- some numbers on Linux x86_64:

 2500 xxhash32 in 1.34ms i.e. 1861504/s or 3.8 GB/s
 2500 crc32c in 943us i.e. 2651113/s or 5.5 GB/s  (SSE4.2 disabled)
 2500 hash32 in 707us i.e. 3536067/s or 7.3 GB/s
 2500 crc32c in 387us i.e. 6459948/s or 13.4 GB/s (SSE4.2 enabled)

1.5.179. Hash32

function Hash32(const Text: RawByteString): cardinal; overload;

Our custom efficient 32-bit hash/checksum function
- a Fletcher-like checksum algorithm, not a hash function: has less colisions than Adler32 for short strings, but more than xxhash32 or crc32/crc32c
- overloaded function using RawByteString for binary content hashing, whatever the codepage is


1.5.180. HasHWAes

function HasHWAes: boolean;

Cross-platform wrapper function to check AES HW support on Intel or ARM


1.5.181. HugePower10Neg

function HugePower10Neg(exponent: PtrInt; pow10: PPow10): TSynExtended;

Low-level computation of 10 ^ negative exponent, if POW10[] is not enough


1.5.182. HugePower10Pos

function HugePower10Pos(exponent: PtrInt; pow10: PPow10): TSynExtended;

Low-level computation of 10 ^ positive exponent, if POW10[] is not enough


1.5.183. InsertInteger

function InsertInteger(var Values: TIntegerDynArray; var ValuesCount: integer; Value: integer; Index: PtrInt; CoValues: PIntegerDynArray = nil): PtrInt;

Insert an integer value at the specified index position of a dynamic array of integers
- if Index is invalid, the Value is inserted at the end of the array


1.5.184. Int64Scan

function Int64Scan(P: PInt64Array; Count: PtrInt; const Value: Int64): PInt64;

Fast search of an integer position in a 64-bit integer array
- Count is the number of Int64 entries in P^
- returns P where P^=Value
- returns nil if Value was not found


1.5.185. Int64ScanExists

function Int64ScanExists(P: PInt64Array; Count: PtrInt; const Value: Int64): boolean;

Fast search of an integer value in a 64-bit integer array
- returns true if P^=Value within Count entries
- returns false if Value was not found


1.5.186. Int64ScanIndex

function Int64ScanIndex(P: PInt64Array; Count: PtrInt; const Value: Int64): PtrInt;

Fast search of an integer position in a signed 64-bit integer array
- Count is the number of Int64 entries in P^
- returns index of P^[index]=Value
- returns -1 if Value was not found


1.5.187. Int64ToCurrency

procedure Int64ToCurrency(const i: Int64; out c: currency); overload;

Convert a Int64 value into a currency
- using multiplication by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.188. Int64ToCurrency

procedure Int64ToCurrency(const i: Int64; c: PCurrency); overload;

Convert a Int64 value into a currency
- using multiplication by CURR_RES (=10000)
- warning: FPC Win64 to Win32 cross-compiler doesn't support currency values properly -> use FPC Win32 compiler only on Windows


1.5.189. IntegerScan

function IntegerScan(P: PCardinalArray; Count: PtrInt; Value: cardinal): PCardinal;

Fast search of an unsigned integer item in a 32-bit integer array
- Count is the number of cardinal entries in P^
- returns P where P^=Value
- returns nil if Value was not found
- is implemented via IntegerScanIndex() SSE2 asm on i386 and x86_64


1.5.190. IntegerScanExists

function IntegerScanExists(P: PCardinalArray; Count: PtrInt; Value: cardinal): boolean;

Fast search of an unsigned integer in a 32-bit integer array
- returns true if P^=Value within Count entries
- returns false if Value was not found
- is implemented via IntegerScanIndex() SSE2 asm on i386 and x86_64


1.5.191. IntegerScanIndex

function IntegerScanIndex(P: PCardinalArray; Count: PtrInt; Value: cardinal): PtrInt;

Fast search of an unsigned integer position in a 32-bit integer array
- Count is the number of integer entries in P^
- return index of P^[index]=Value
- return -1 if Value was not found
- is implemented with SSE2 asm on i386 and x86_64


1.5.192. InterfaceArrayAdd

function InterfaceArrayAdd(var aInterfaceArray; const aItem: IUnknown): PtrInt;

Wrapper to add an item to a T*InterfaceArray dynamic array storage


1.5.193. InterfaceArrayAddCount

function InterfaceArrayAddCount(var aInterfaceArray; var aCount: integer; const aItem: IUnknown): PtrInt;

Wrapper to add an item to a T*InterfaceArray dynamic array storage


1.5.194. InterfaceArrayAddOnce

procedure InterfaceArrayAddOnce(var aInterfaceArray; const aItem: IUnknown);

Wrapper to add once an item to a T*InterfaceArray dynamic array storage


1.5.195. InterfaceArrayDelete

procedure InterfaceArrayDelete(var aInterfaceArray; aItemIndex: PtrInt); overload;

Wrapper to delete an item in a T*InterfaceArray dynamic array storage
- do nothing if the item is not found in the dynamic array


1.5.196. InterfaceArrayDelete

function InterfaceArrayDelete(var aInterfaceArray; const aItem: IUnknown): PtrInt; overload;

Wrapper to delete an item in a T*InterfaceArray dynamic array storage
- search is performed by address/reference, not by content
- do nothing if the item is not found in the dynamic array


1.5.197. InterfaceArrayFind

function InterfaceArrayFind(const aInterfaceArray; const aItem: IUnknown): PtrInt;

Wrapper to search an item in a T*InterfaceArray dynamic array storage
- search is performed by address/reference, not by content
- return -1 if the item is not found in the dynamic array, or the index of the matching entry otherwise


1.5.198. InterfaceNilSafe

procedure InterfaceNilSafe(var aInterface);

Same as aInterface := nil but ignoring any exception


1.5.199. InterfacesNilSafe

procedure InterfacesNilSafe(const aInterfaces: array of pointer);

Same as aInterface := nil but ignoring any exception


1.5.200. InterlockedDecrement

function InterlockedDecrement(var I: integer): integer;

Compatibility function, to be implemented according to the running CPU
- expect the same result as the homonymous Win32 API function, i.e. returns I - 1, and store I - 1 within I in an atomic/tread-safe way
- FPC will define this function as intrinsic for non-Intel CPUs


1.5.201. InterlockedIncrement

function InterlockedIncrement(var I: integer): integer;

Compatibility function, to be implemented according to the running CPU
- expect the same result as the homonymous Win32 API function, i.e. returns I + 1, and store I + 1 within I in an atomic/tread-safe way
- FPC will define this function as intrinsic for non-Intel CPUs


1.5.202. IsAnsiCompatible

function IsAnsiCompatible(PC: PAnsiChar): boolean; overload;

Return TRUE if the supplied buffer only contains 7-bits Ansi characters


1.5.203. IsAnsiCompatible

function IsAnsiCompatible(PC: PAnsiChar; Len: PtrUInt): boolean; overload;

Return TRUE if the supplied buffer only contains 7-bits Ansi characters


1.5.204. IsAnsiCompatible

function IsAnsiCompatible(const Text: RawByteString): boolean; overload;

Return TRUE if the supplied text only contains 7-bits Ansi characters


1.5.205. IsAnsiCompatibleW

function IsAnsiCompatibleW(PW: PWideChar; Len: PtrInt): boolean; overload;

Return TRUE if the supplied UTF-16 buffer only contains 7-bits Ansi characters


1.5.206. IsAnsiCompatibleW

function IsAnsiCompatibleW(PW: PWideChar): boolean; overload;

Return TRUE if the supplied UTF-16 buffer only contains 7-bits Ansi characters


1.5.207. IsEqual

function IsEqual(const A, B: THash512): boolean; overload;

Returns TRUE if all 64 bytes of both 512-bit buffers do match
- e.g. two SHA-512 digests
- this function is not sensitive to any timing attack, so is designed for cryptographic purpose


1.5.208. IsEqual

function IsEqual(const A, B; count: PtrInt): boolean; overload;

Returns TRUE if all bytes of both buffers do match
- this function is not sensitive to any timing attack, so is designed for cryptographic purposes - use CompareMem/CompareMemSmall/CompareMemFixed as faster alternatives for general-purpose code


1.5.209. IsEqual

function IsEqual(const A, B: THash256): boolean; overload;

Returns TRUE if all 32 bytes of both 256-bit buffers do match
- e.g. a SHA-256 digest, or a TEccSignature result
- this function is not sensitive to any timing attack, so is designed for cryptographic purpose


1.5.210. IsEqual

function IsEqual(const A, B: THash160): boolean; overload;

Returns TRUE if all 20 bytes of both 160-bit buffers do match
- e.g. a SHA-1 digest
- this function is not sensitive to any timing attack, so is designed for cryptographic purpose


1.5.211. IsEqual

function IsEqual(const A, B: THash128): boolean; overload;

Returns TRUE if all 16 bytes of both 128-bit buffers do match
- e.g. a MD5 digest, or an AES block
- this function is not sensitive to any timing attack, so is designed for cryptographic purpose - and it is also branchless therefore fast


1.5.212. IsEqual

function IsEqual(const A, B: THash384): boolean; overload;

Returns TRUE if all 48 bytes of both 384-bit buffers do match
- e.g. a SHA-384 digest
- this function is not sensitive to any timing attack, so is designed for cryptographic purpose


1.5.213. IsEqualGuid

function IsEqualGuid(const guid1, guid2: TGuid): boolean; overload;

Compare two TGuid values
- this version is faster than the one supplied by SysUtils


1.5.214. IsEqualGuid

function IsEqualGuid(guid1, guid2: PGuid): boolean; overload;

Compare two TGuid values
- this version is faster than the one supplied by SysUtils


1.5.215. IsEqualGuidArray

function IsEqualGuidArray(const guid: TGuid; const guids: array of TGuid): integer;

Returns the index of a matching TGuid in an array
- returns -1 if no item matched


1.5.216. IsNullGuid

function IsNullGuid(const guid: TGuid): boolean;

Check if a TGuid value contains only 0 bytes
- this version is faster than the one supplied by SysUtils


1.5.217. IsZero

function IsZero(const dig: THash160): boolean; overload;

Returns TRUE if all 20 bytes of this 160-bit buffer equal zero
- e.g. a SHA-1 digest


1.5.218. IsZero

function IsZero(P: pointer; Length: integer): boolean; overload;

Returns TRUE if all bytes equal zero


1.5.219. IsZero

function IsZero(const dig: THash256): boolean; overload;

Returns TRUE if all 32 bytes of this 256-bit buffer equal zero
- e.g. a SHA-256 digest, or a TEccSignature result


1.5.220. IsZero

function IsZero(const Values: TInt64DynArray): boolean; overload;

Returns TRUE if Value is nil or all supplied Values[] equal 0


1.5.221. IsZero

function IsZero(const dig: THash384): boolean; overload;

Returns TRUE if all 48 bytes of this 384-bit buffer equal zero
- e.g. a SHA-384 digest


1.5.222. IsZero

function IsZero(const dig: THash128): boolean; overload;

Returns TRUE if all 16 bytes of this 128-bit buffer equal zero
- e.g. a MD5 digest, or an AES block


1.5.223. IsZero

function IsZero(const dig: THash512): boolean; overload;

Returns TRUE if all 64 bytes of this 512-bit buffer equal zero
- e.g. a SHA-512 digest


1.5.224. IsZero

function IsZero(const Values: TIntegerDynArray): boolean; overload;

Returns TRUE if Value is nil or all supplied Values[] equal 0


1.5.225. IsZeroSmall

function IsZeroSmall(P: pointer; Length: PtrInt): boolean;

Returns TRUE if all of a few bytes equal zero
- to be called instead of IsZero() e.g. for 1..8 bytes


1.5.226. KahanSum

procedure KahanSum(const Data: double; var Sum, Carry: double);

Compute the sum of values, using a running compensation for lost low-order bits
- a naive "Sum := Sum + Data" will be restricted to 53 bits of resolution, so will eventually result in an incorrect number
- Kahan algorithm keeps track of the accumulated error in integer operations, to achieve a precision of more than 100 bits
- see https://en.wikipedia.org/wiki/Kahan_summation_algorithm


1.5.227. kr32

function kr32(crc: cardinal; buf: PAnsiChar; len: PtrInt): cardinal;

Standard Kernighan & Ritchie hash from "The C programming Language", 3rd edition
- simple and efficient code, but too much collisions for THasher
- kr32() is 898.8 MB/s - crc32cfast() 1.7 GB/s, crc32csse42() 4.3 GB/s


1.5.228. Lecuyer

function Lecuyer: PLecuyer;

Return the 32-bit Pierre L'Ecuyer software generator for the current thread
- can be used as an alternative to several Random32 function calls


1.5.229. LecuyerEncrypt

procedure LecuyerEncrypt(key: Qword; var data: RawByteString);

Cipher/uncipher some memory buffer using a 64-bit seed and Pierre L'Ecuyer's algorithm, and its gsl_rng_taus2 generator


1.5.230. LockedAdd

procedure LockedAdd(var Target: PtrUInt; Increment: PtrUInt);

Fast atomic addition operation on a pointer-sized integer value
- via Intel/AMD custom asm or FPC RTL InterlockedExchangeAdd(pointer)
- Target should be aligned, which is the case when defined as a class field


1.5.231. LockedAdd32

procedure LockedAdd32(var Target: cardinal; Increment: cardinal);

Fast atomic addition operation on a 32-bit integer value
- via Intel/AMD custom asm or FPC RTL InterlockedExchangeAdd(pointer)
- Target should be aligned, which is the case when defined as a class field


1.5.232. LockedDec

procedure LockedDec(var Target: PtrUInt; Decrement: PtrUInt);

Fast atomic substraction operation on a pointer-sized integer value
- via Intel/AMD custom asm or FPC RTL InterlockedExchangeAdd(-pointer)
- Target should be aligned, which is the case when defined as a class field


1.5.233. LockedDec32

procedure LockedDec32(int32: PInteger);

Slightly faster than InterlockedDecrement() when you don't need the result


1.5.234. LockedExc

function LockedExc(var Target: PtrUInt; NewValue, Comperand: PtrUInt): boolean;

Fast atomic compare-and-swap operation on a pointer-sized integer value
- via Intel/AMD custom asm or FPC RTL InterlockedCompareExchange(pointer)
- true if Target was equal to Comparand, and Target set to NewValue
- used e.g. as thread-safe atomic operation for TLightLock/TRWLock
- Target should be aligned, which is the case when defined as a class field


1.5.235. LockedInc32

procedure LockedInc32(int32: PInteger);

Slightly faster than InterlockedIncrement() when you don't need the result


1.5.236. LockedInc64

procedure LockedInc64(int64: PInt64);

Slightly faster than InterlockedIncrement64()


1.5.237. MemCmp

function MemCmp(P1, P2: PByteArray; L: PtrInt): integer;

Binary comparison of buffers, returning <0, 0 or >0 results
- caller should ensure that P1<>nil, P2<>nil and L>0
- on x86_64, will use a fast SSE2 asm version of the C function memcmp() (which is also used by CompareMem and CompareBuf)
- on other platforms, run a simple but efficient per-byte comparison


1.5.238. MoveAndZero

procedure MoveAndZero(Source, Dest: pointer; Count: PtrUInt);

Perform a MoveFast then fill the Source buffer with zeros
- could be used e.g. to quickly move a managed record content into a newly allocated stack variable with no reference counting


1.5.239. MoveByOne

procedure MoveByOne(Source, Dest: pointer; Count: PtrUInt);

Move() with one-by-one byte copy
- never redirect to MoveFast() so could be used when data overlaps


1.5.240. MoveFast

procedure MoveFast(const src; var dst; cnt: PtrInt);

Our fast version of move() on Intel/AMD
- on Delphi Intel i386/x86_64, will use fast SSE2 instructions (if available)
- FPC i386 has fastmove.inc which is faster than our SSE2/ERMS version
- FPC x86_64 RTL is slower than our SSE2/AVX asm
- on non-Intel CPUs, it will fallback to the default RTL Move()
- on ARM/AARCH64 POSIX, mormot.core.os would redirect to optimized libc


1.5.241. MoveSwap

procedure MoveSwap(dst, src: PByte; n: PtrInt);

Copy one memory buffer to another, swapping the bytes order
- used e.g. by TBigInt.Load/Save to follow DER big-endian encoding
- warning: src and dst should not overlap


1.5.242. mul64x64

procedure mul64x64(const left, right: QWord; out product: THash128Rec);

Fast computation of two 64-bit unsigned integers into a 128-bit value


1.5.243. MultiEventAdd

function MultiEventAdd(var EventList; const Event: TMethod): boolean;

Low-level wrapper to add a callback to a dynamic list of events
- by default, you can assign only one callback to an Event: but by storing it as a dynamic array of events, you can use this wrapper to add one callback to this list of events
- if the event was already registered, do nothing (i.e. won't call it twice)
- since this function uses an unsafe typeless EventList parameter, you should not use it in high-level code, but only as wrapper within dedicated methods
- will add Event to EventList[] unless Event is already registered
- is used e.g. by TJsonWriter as such:

 ...
   fEchos: array of TOnTextWriterEcho;
 ...
   procedure EchoAdd(const aEcho: TOnTextWriterEcho);
 ...
 procedure TEchoWriter.EchoAdd(const aEcho: TOnTextWriterEcho);
 begin
   MultiEventAdd(fEchos,TMethod(aEcho));
 end;

then callbacks are then executed as such:

 if fEchos<>nil then
   for i := 0 to length(fEchos) - 1 do
     fEchos[i](self,fEchoBuf);

- use MultiEventRemove() to un-register a callback from the list


1.5.244. MultiEventFind

function MultiEventFind(const EventList; const Event: TMethod): PtrInt;

Low-level wrapper to check if a callback is in a dynamic list of events
- by default, you can assign only one callback to an Event: but by storing it as a dynamic array of events, you can use this wrapper to check if a callback has already been registered to this list of events
- used internally by MultiEventAdd() and MultiEventRemove() functions


1.5.245. MultiEventMerge

procedure MultiEventMerge(var DestList; const ToBeAddedList);

Low-level wrapper to add one or several callbacks from another list of events
- all events of the ToBeAddedList would be added to DestList
- the list is not checked for duplicates


1.5.246. MultiEventRemove

procedure MultiEventRemove(var EventList; const Event: TMethod); overload;

Low-level wrapper to remove a callback from a dynamic list of events
- by default, you can assign only one callback to an Event: but by storing it as a dynamic array of events, you can use this wrapper to remove one callback already registered by MultiEventAdd() to this list of events
- since this function uses an unsafe typeless EventList parameter, you should not use it in high-level code, but only as wrapper within dedicated methods
- is used e.g. by TJsonWriter as such:

 ...
   fEchos: array of TOnTextWriterEcho;
 ...
   procedure EchoRemove(const aEcho: TOnTextWriterEcho);
 ...
 procedure TJsonWriter.EchoRemove(const aEcho: TOnTextWriterEcho);
 begin
   MultiEventRemove(fEchos,TMethod(aEcho));
 end;

1.5.247. MultiEventRemove

procedure MultiEventRemove(var EventList; Index: PtrInt); overload;

Low-level wrapper to remove a callback from a dynamic list of events
- same as the same overloaded procedure, but accepting an EventList[] index to identify the Event to be suppressed


1.5.248. NextGrow

function NextGrow(capacity: integer): integer;

Compute the new capacity when expanding an array of items
- handle tiny, small, medium, large and huge sizes properly to reduce memory usage and maximize performance
- initial steps are 4, 8, 12, 28, 40, 56, 72, 88, 104, 120, 136, 170, 212, 265, 331, 413, 516, 645, 806, 1007, 1258, 1572, ...


1.5.249. ObjArrayAdd

function ObjArrayAdd(var aObjArray; aItem: TObject): PtrInt; overload;

Wrapper to add an item to a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- could be used as such (note the T*ObjArray type naming convention):

 TUserObjArray = array of TUser;
 ...
 var arr: TUserObjArray;
     user: TUser;
 ..
 try
   user := TUser.Create;
   user.Name := 'Name';
   index := ObjArrayAdd(arr,user);
 ...
 finally
   ObjArrayClear(arr); // release all items
 end;

- return the index of the item in the dynamic array


1.5.250. ObjArrayAddCount

function ObjArrayAddCount(var aObjArray; aItem: TObject; var aObjArrayCount: integer): PtrInt;

Wrapper to add an item to a T*ObjArray dynamic array storage
- this overloaded function will use a separated variable to store the items count, so will be slightly faster: but you should call SetLength() when done, to have a stand-alone array as expected by our ORM/SOA serialziation
- return the index of the item in the dynamic array


1.5.251. ObjArrayAddFrom

function ObjArrayAddFrom(var aDestObjArray; const aSourceObjArray): PtrInt;

Wrapper to add items to a T*ObjArray dynamic array storage
- aSourceObjArray[] items are just copied to aDestObjArray, which remains untouched
- return the new number of the items in aDestObjArray


1.5.252. ObjArrayAddOnce

function ObjArrayAddOnce(var aObjArray; aItem: TObject; var aObjArrayCount: integer): PtrInt; overload;

Wrapper to add once an item to a T*ObjArray dynamic array storage and Count


1.5.253. ObjArrayAddOnce

function ObjArrayAddOnce(var aObjArray; aItem: TObject): PtrInt; overload;

Wrapper to add once an item to a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- if the object is already in the array (searching by address/reference, not by content), return its current index in the dynamic array
- if the object does not appear in the array, add it at the end


1.5.254. ObjArrayAddOnceFrom

function ObjArrayAddOnceFrom(var aDestObjArray; const aSourceObjArray): PtrInt;

- aSourceObjArray[] items are just copied to aDestObjArray, which remains untouched
- will first check if aSourceObjArray[] items are not already in aDestObjArray
- return the new number of the items in aDestObjArray


1.5.255. ObjArrayAppend

function ObjArrayAppend(var aDestObjArray, aSourceObjArray): PtrInt;

Wrapper to add and move items to a T*ObjArray dynamic array storage
- aSourceObjArray[] items will be owned by aDestObjArray[], therefore aSourceObjArray is set to nil
- return the new number of the items in aDestObjArray


1.5.256. ObjArrayClear

procedure ObjArrayClear(var aObjArray); overload;

Wrapper to release all items stored in a T*ObjArray dynamic array
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- you should always use ObjArrayClear() before the array storage is released, e.g. in the owner class destructor
- when T*ObjArray are used as SOA parameters, no need to release the values
- will also set the dynamic array length to 0, so could be used to re-use an existing T*ObjArray


1.5.257. ObjArrayClear

procedure ObjArrayClear(var aObjArray; aCount: integer); overload;

Wrapper to release all items stored in a T*ObjArray dynamic array
- this overloaded function will use the supplied array length as parameter
- you should always use ObjArrayClear() before the array storage is released, e.g. in the owner class destructor
- will also set the dynamic array length to 0, so could be used to re-use an existing T*ObjArray


1.5.258. ObjArrayClear

procedure ObjArrayClear(var aObjArray; aContinueOnException: boolean; aCount: PInteger = nil); overload;

Wrapper to release all items stored in a T*ObjArray dynamic array
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- you should always use ObjArrayClear() before the array storage is released, e.g. in the owner class destructor
- will also set the dynamic array length to 0, so could be used to re-use an existing T*ObjArray


1.5.259. ObjArrayDelete

function ObjArrayDelete(var aObjArray; var aCount: integer; aItem: TObject): PtrInt; overload;

Wrapper to delete an item in a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- search is performed by address/reference, not by content
- do nothing if the item is not found in the dynamic array


1.5.260. ObjArrayDelete

procedure ObjArrayDelete(var aObjArray; aItemIndex: PtrInt; const aContinueOnException: boolean = false; aCount: PInteger = nil); overload;

Wrapper to delete an item in a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- do nothing if the index is out of range in the dynamic array


1.5.261. ObjArrayDelete

function ObjArrayDelete(var aObjArray; aItem: TObject): PtrInt; overload;

Wrapper to delete an item in a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- search is performed by address/reference, not by content
- do nothing if the item is not found in the dynamic array


1.5.262. ObjArrayFind

function ObjArrayFind(const aObjArray; aCount: integer; aItem: TObject): PtrInt; overload;

Wrapper to search an item in a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- search is performed by address/reference, not by content
- returns -1 if the item is not found in the dynamic array


1.5.263. ObjArrayFind

function ObjArrayFind(const aObjArray; aItem: TObject): PtrInt; overload;

Wrapper to search an item in a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()
- search is performed by address/reference, not by content
- returns -1 if the item is not found in the dynamic array


1.5.264. ObjArrayNotNilCount

function ObjArrayNotNilCount(const aObjArray): integer;

Wrapper to count all not nil items in a T*ObjArray dynamic array storage
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()


1.5.265. ObjArrayObjArrayClear

procedure ObjArrayObjArrayClear(var aObjArray);

Wrapper to release all items stored in an array of T*ObjArray dynamic array
- e.g. aObjArray may be defined as "array of array of TSynFilter"


1.5.266. ObjArraysClear

procedure ObjArraysClear(const aObjArray: array of pointer);

Wrapper to release all items stored in several T*ObjArray dynamic arrays
- for proper serialization on Delphi 7-2009, use Rtti.RegisterObjArray()


1.5.267. ObjArraySetLength

procedure ObjArraySetLength(var aObjArray; aLength: integer);

Wrapper to set the length of a T*ObjArray dynamic array storage
- could be used as an alternative to SetLength() when you do not know the exact T*ObjArray type


1.5.268. OrMemory

procedure OrMemory(Dest, Source: PByteArray; size: PtrInt);

Logical OR of two memory buffers
- will perform on all buffer bytes:

 Dest[i] := Dest[i] or Source[i];

1.5.269. PosChar

function PosChar(Str: PUtf8Char; Chr: AnsiChar): PUtf8Char; overload;

Fast retrieve the position of a given character in a #0 ended buffer
- will use fast SSE2 asm on i386 and x86_64


1.5.270. PosChar

function PosChar(Str: PUtf8Char; StrLen: PtrInt; Chr: AnsiChar): PUtf8Char; overload;

Fast retrieve the position of a given character in a #0 ended buffer
- will use fast SSE2 asm on i386 and x86_64


1.5.271. PosEx

function PosEx(const SubStr, S: RawUtf8; Offset: PtrUInt = 1): PtrInt;

Faster RawUtf8 Equivalent of standard StrUtils.PosEx


1.5.272. PosExChar

function PosExChar(Chr: AnsiChar; const Str: RawUtf8): PtrInt;

Optimized version of PosEx() with search text as one AnsiChar
- will use fast SSE2 asm on i386 and x86_64


1.5.273. PosExString

function PosExString(const SubStr, S: string; Offset: PtrUInt = 1): PtrInt;

Our own PosEx() function dedicated to RTL string process
- Delphi XE or older don't support Pos() with an Offset


1.5.274. PropNameEquals

function PropNameEquals(const P1, P2: RawUtf8): boolean; overload;

Delphi has troubles inlining goto/label case-insensitive comparison of two RawUtf8 only containing ASCII 7-bit
- use e.g. with RTTI property names values only including A..Z,0..9,_ chars
- will make the "XOR AND $DF" trick to quickly test A-Z / a-z characters
- behavior is undefined with UTF-8 encoding (some false positive may occur)
- see IdemPropName/IdemPropNameU functions in mormot.core.text for a similar comparison with other kind of input variables


1.5.275. PropNameEquals

function PropNameEquals(P1, P2: PShortString): boolean; overload;

Case-insensitive comparison of two shortstrings only containing ASCII 7-bit
- use e.g. with RTTI property names values only including A..Z,0..9,_ chars
- will make the "XOR AND $DF" trick to quickly test A-Z / a-z characters
- behavior is undefined with UTF-8 encoding (some false positive may occur)
- see IdemPropName/IdemPropNameU functions in mormot.core.text for a similar comparison with other kind of input variables


1.5.276. PtrArrayAdd

function PtrArrayAdd(var aPtrArray; aItem: pointer): integer; overload;

Wrapper to add an item to a array of pointer dynamic array storage


1.5.277. PtrArrayAdd

function PtrArrayAdd(var aPtrArray; aItem: pointer; var aPtrArrayCount: integer): PtrInt; overload;

Wrapper to add an item to a array of pointer dynamic array storage


1.5.278. PtrArrayAddOnce

function PtrArrayAddOnce(var aPtrArray; aItem: pointer; var aPtrArrayCount: integer): PtrInt; overload;

Wrapper to add once an item to a array of pointer dynamic array storage


1.5.279. PtrArrayAddOnce

function PtrArrayAddOnce(var aPtrArray; aItem: pointer): PtrInt; overload;

Wrapper to add once an item to a array of pointer dynamic array storage


1.5.280. PtrArrayDelete

procedure PtrArrayDelete(var aPtrArray; aIndex: PtrInt; aCount: PInteger = nil; aKind: TPtrArrayKind = pakPointer); overload;

Wrapper to delete an item from a array of pointer dynamic array storage


1.5.281. PtrArrayDelete

function PtrArrayDelete(var aPtrArray; aItem: pointer; aCount: PInteger = nil; aKind: TPtrArrayKind = pakPointer): PtrInt; overload;

Wrapper to delete an item from a array of pointer dynamic array storage


1.5.282. PtrArrayFind

function PtrArrayFind(var aPtrArray; aItem: pointer): integer;

Wrapper to find an item to a array of pointer dynamic array storage


1.5.283. PtrArrayInsert

function PtrArrayInsert(var aPtrArray; aItem: pointer; aIndex: PtrInt; var aPtrArrayCount: integer): PtrInt; overload;

Wrapper to insert an item to a array of pointer dynamic array storage


1.5.284. PtrUIntScan

function PtrUIntScan(P: PPtrUIntArray; Count: PtrInt; Value: PtrUInt): pointer;

Fast search of a pointer-sized unsigned integer in an pointer-sized integer array
- Count is the number of pointer-sized integer entries in P^
- returns true if P^=Value within Count entries
- returns false if Value was not found


1.5.285. PtrUIntScanExists

function PtrUIntScanExists(P: PPtrUIntArray; Count: PtrInt; Value: PtrUInt): boolean;

Fast search of a pointer-sized unsigned integer position in an pointer-sized integer array
- Count is the number of pointer-sized integer entries in P^
- returns true if P^=Value within Count entries
- returns false if Value was not found


1.5.286. PtrUIntScanIndex

function PtrUIntScanIndex(P: PPtrUIntArray; Count: PtrInt; Value: PtrUInt): PtrInt;

Fast search of a pointer-sized unsigned integer position in an pointer-sized integer array
- Count is the number of pointer-sized integer entries in P^
- return index of P^[index]=Value
- return -1 if Value was not found


1.5.287. QuickSortDouble

procedure QuickSortDouble(ID: PDoubleArray; L, R: PtrInt);

Sort a double array, low values first


1.5.288. QuickSortInt64

procedure QuickSortInt64(ID: PInt64Array; L, R: PtrInt); overload;

Sort a 64-bit signed integer array, low values first


1.5.289. QuickSortInt64

procedure QuickSortInt64(ID, CoValues: PInt64Array; L, R: PtrInt); overload;

Sort a 64-bit integer array, low values first


1.5.290. QuickSortInteger

procedure QuickSortInteger(var ID: TIntegerDynArray); overload;

Sort an integer array, low values first


1.5.291. QuickSortInteger

procedure QuickSortInteger(ID: PIntegerArray; L, R: PtrInt); overload;

Sort an integer array, low values first


1.5.292. QuickSortInteger

procedure QuickSortInteger(ID, CoValues: PIntegerArray; L, R: PtrInt); overload;

Sort an integer array, low values first


1.5.293. QuickSortPointer

procedure QuickSortPointer(P: PPointerArray; L, R: PtrInt);

Sort a pointer array, low values first


1.5.294. QuickSortPtrInt

procedure QuickSortPtrInt(P: PPtrIntArray; L, R: PtrInt);

Sort a PtrInt array, low values first


1.5.295. QuickSortQWord

procedure QuickSortQWord(ID: PQWordArray; L, R: PtrInt); overload;

Sort a 64-bit unsigned integer array, low values first
- QWord comparison are implemented correctly under FPC or Delphi 2009+ - older compilers will use fast and exact SortDynArrayQWord()


1.5.296. QuickSortWord

procedure QuickSortWord(ID: PWordArray; L, R: PtrInt);

Sort a 16-bit unsigned integer array, low values first


1.5.297. QWordScanIndex

function QWordScanIndex(P: PQWordArray; Count: PtrInt; const Value: QWord): PtrInt;

Fast search of an integer position in an unsigned 64-bit integer array
- Count is the number of QWord entries in P^
- returns index of P^[index]=Value
- returns -1 if Value was not found


1.5.298. RaiseStreamError

function RaiseStreamError(Caller: TObject; const Context: shortstring): PtrInt;

Raise a EStreamError exception - e.g. from TSynMemoryStream.Write


1.5.299. Random31

function Random31: integer;

Fast compute of some 31-bit random value, using the gsl_rng_taus2 generator
- thread-safe function: each thread will maintain its own TLecuyer table


1.5.300. Random31Not0

function Random31Not0: integer;

Compute of a 31-bit random value <> 0, using the gsl_rng_taus2 generator
- thread-safe function: each thread will maintain its own TLecuyer table


1.5.301. Random32

function Random32(max: cardinal): cardinal; overload;

Fast compute of bounded 32-bit random value, using the gsl_rng_taus2 generator
- calls internally the overloaded Random32 function, ensuring Random32(max)<max
- consider using TAesPrng.Main.Random32(), which offers cryptographic-level randomness, but is twice slower (even with AES-NI)
- thread-safe and non-blocking function using a per-thread TLecuyer engine


1.5.302. Random32

function Random32: cardinal; overload;

Fast compute of some 32-bit random value, using the gsl_rng_taus2 generator
- this function will use well documented and proven Pierre L'Ecuyer software generator - which happens to be faster (and safer) than RDRAND opcode (which is used for seeding anyway)
- consider using TAesPrng.Main.Random32(), which offers cryptographic-level randomness, but is twice slower (even with AES-NI)
- thread-safe and non-blocking function: each thread will maintain its own TLecuyer table (note that RTL's system.Random function is not thread-safe)


1.5.303. Random32Seed

procedure Random32Seed(entropy: pointer = nil; entropylen: PtrInt = 0);

Seed the thread-specific gsl_rng_taus2 Random32 generator
- by default, gsl_rng_taus2 generator is re-seeded every 2^32 values, which is very conservative against the Pierre L'Ecuyer's algorithm period of 2^88
- you can specify some additional entropy buffer; note that calling this function with the same entropy again WON'T seed the generator with the same sequence (as with RTL's RandomSeed function), but initiate a new one
- calls XorEntropy(), so RdRand32/Rdtsc opcodes on Intel/AMD CPUs
- thread-safe and non-blocking function using a per-thread TLecuyer engine


1.5.304. Random64

function Random64: QWord;

Fast compute of a 64-bit random value, using the gsl_rng_taus2 generator
- thread-safe function: each thread will maintain its own TLecuyer table


1.5.305. RandomBytes

procedure RandomBytes(Dest: PByte; Count: integer);

Fill a memory buffer with random bytes from the gsl_rng_taus2 generator
- will actually XOR the Dest buffer with Lecuyer numbers
- consider also the cryptographic-level TAesPrng.Main.FillRandom() method
- thread-safe and non-blocking function using a per-thread TLecuyer engine


1.5.306. RandomDouble

function RandomDouble: double;

Fast compute of a 64-bit random floating point, using the gsl_rng_taus2 generator
- thread-safe and non-blocking function using a per-thread TLecuyer engine


1.5.307. RandomGuid

procedure RandomGuid(out result: TGuid); overload;

Compute a random UUid value from the RandomBytes() generator and RFC 4122


1.5.308. RandomGuid

function RandomGuid: TGuid; overload;

Compute a random UUid value from the RandomBytes() generator and RFC 4122


1.5.309. RandomShort31

procedure RandomShort31(var dest: TShort31);

Fill some string[31] with 7-bit ASCII random text
- thread-safe and non-blocking function using a per-thread TLecuyer engine


1.5.310. RawByteStringToVariant

procedure RawByteStringToVariant(Data: PByte; DataLen: integer; var Value: variant); overload;

Convert a raw binary buffer into a variant RawByteString varString
- you can then use VariantToRawByteString() to retrieve the binary content


1.5.311. RawByteStringToVariant

procedure RawByteStringToVariant(const Data: RawByteString; var Value: variant); overload;

Convert a RawByteString content into a variant varString
- you can then use VariantToRawByteString() to retrieve the binary content


1.5.312. RawObjectsClear

procedure RawObjectsClear(o: PObject; n: integer);

Low-level function calling FreeAndNil(o^) successively n times


1.5.313. RawUtf8ToVariant

procedure RawUtf8ToVariant(Txt: PUtf8Char; TxtLen: integer; var Value: variant); overload;

Convert an UTF-8 encoded text buffer into a variant RawUtf8 varString


1.5.314. RawUtf8ToVariant

procedure RawUtf8ToVariant(const Txt: RawUtf8; var Value: variant); overload;

Convert an UTF-8 encoded string into a variant RawUtf8 varString


1.5.315. RawUtf8ToVariant

function RawUtf8ToVariant(const Txt: RawUtf8): variant; overload;

Convert an UTF-8 encoded string into a variant RawUtf8 varString


1.5.316. Rcu

procedure Rcu(var src, dst; len: integer);

Thread-safe move of a memory buffer using a simple Read-Copy-Update pattern


1.5.317. Rcu128

procedure Rcu128(var src, dst);

Thread-safe move of a 128-bit value using a simple Read-Copy-Update pattern


1.5.318. Rcu32

procedure Rcu32(var src, dst);

Thread-safe move of a 32-bit value using a simple Read-Copy-Update pattern


1.5.319. Rcu64

procedure Rcu64(var src, dst);

Thread-safe move of a 64-bit value using a simple Read-Copy-Update pattern


1.5.320. RcuPtr

procedure RcuPtr(var src, dst);

Thread-safe move of a pointer value using a simple Read-Copy-Update pattern


1.5.321. RdRand32

procedure RdRand32(buffer: PCardinal; n: integer); overload;

XOR a memory buffer with some random generated by modern Intel CPU
- n is the number of 32-bit slots in the supplied buffer to fill
- will do nothing if cfSSE42 is not available on this CPU


1.5.322. RdRand32

function RdRand32: cardinal; overload;

Compute 32-bit random number generated by modern Intel CPU hardware
- using NIST SP 800-90A and FIPS 140-2 compliant RDRAND Intel x86/x64 opcode
- caller should ensure that cfSSE42 is included in CpuFeatures flags
- you should rather call XorEntropy() which offers additional sources


1.5.323. Rdtsc

function Rdtsc: Int64;

Returns the 64-bit Intel Time Stamp Counter (TSC)
- could be used as entropy source for randomness - use TPrecisionTimer if you expect a cross-platform and cross-CPU high resolution performance counter


1.5.324. ReadBarrier

procedure ReadBarrier;

This function is an intrinsic in FPC


1.5.325. RleCompress

function RleCompress(src, dst: PByteArray; srcsize, dstsize: PtrUInt): PtrInt;

Simple Run-Length-Encoding compression of a memory buffer
- SynLZ is not good with input of a lot of redundant bytes, e.g. chunks of zeros: you could pre-process RleCompress/RleUnCompress such data before SynLZ
- see AlgoRleLZ as such a RLE + SynLZ algorithm
- returns the number of bytes written to dst, or -1 on dstsize overflow


1.5.326. RleUnCompress

function RleUnCompress(src, dst: PByteArray; size: PtrUInt): PtrUInt;

Simple Run-Length-Encoding uncompression of a memory buffer
- SynLZ is not good with input of a lot of redundant bytes, e.g. chunks of zeros: you could pre-process RleCompress/RleUnCompress such data before SynLZ
- see AlgoRleLZ as such a RLE + SynLZ algorithm


1.5.327. RleUnCompressPartial

function RleUnCompressPartial(src, dst: PByteArray; size, max: PtrUInt): PtrUInt;

Partial Run-Length-Encoding uncompression of a memory buffer


1.5.328. SameValue

function SameValue(const A, B: Double; DoublePrec: double = DOUBLE_SAME): boolean;

Compare to floating point values, with IEEE 754 double precision
- use this function instead of raw = operator
- the precision is calculated from the A and B value range
- faster equivalent than SameValue() in Math unit
- if you know the precision range of A and B, it's faster to check abs(A-B)<range


1.5.329. SameValueFloat

function SameValueFloat(const A, B: TSynExtended; DoublePrec: TSynExtended = DOUBLE_SAME): boolean;

Compare to floating point values, with IEEE 754 double precision
- use this function instead of raw = operator
- the precision is calculated from the A and B value range
- faster equivalent than SameValue() in Math unit
- if you know the precision range of A and B, it's faster to check abs(A-B)<range


1.5.330. SetBit

procedure SetBit(var Bits; aIndex: PtrInt);

Set a particular bit into a bit array
- this function can't be inlined, whereas SetBitPtr() function can


1.5.331. SetBit64

procedure SetBit64(var Bits: Int64; aIndex: PtrInt);

Set a particular bit into a 64-bit integer bits (max aIndex is 63)


1.5.332. SetBitPtr

procedure SetBitPtr(Bits: pointer; aIndex: PtrInt);

Set a particular bit into a bit array
- SetBit() can't be inlined, whereas this pointer-oriented function can


1.5.333. SetInt64

procedure SetInt64(P: PUtf8Char; var result: Int64);

Get the 64-bit signed integer value stored in P^


1.5.334. SetQWord

procedure SetQWord(P: PUtf8Char; var result: QWord); overload;

Get the 64-bit unsigned integer value stored in P^


1.5.335. SetQWord

procedure SetQWord(P, PEnd: PUtf8Char; var result: QWord); overload;

Get the 64-bit unsigned integer value stored in P^


1.5.336. SetVariantNull

procedure SetVariantNull(var Value: variant);

Same as Value := Null, but slightly faster


1.5.337. SetVariantUnRefSimpleValue

function SetVariantUnRefSimpleValue(const Source: variant; var Dest: TVarData): boolean;

Same as Dest := TVarData(Source) for simple values
- will return TRUE for all simple values after varByRef unreference, and copying the unreferenced Source value into Dest raw storage
- will return FALSE for not varByRef values, or complex values (e.g. string)


1.5.338. ShortStringToAnsi7String

function ShortStringToAnsi7String(const source: ShortString): RawByteString; overload;

Direct conversion of an ANSI-7 ShortString into an AnsiString
- can be used e.g. for names retrieved from RTTI to convert them into RawUtf8


1.5.339. ShortStringToAnsi7String

procedure ShortStringToAnsi7String(const source: ShortString; var result: RawUtf8); overload;

Direct conversion of an ANSI-7 ShortString into an AnsiString
- can be used e.g. for names retrieved from RTTI to convert them into RawUtf8


1.5.340. SimpleRoundTo2Digits

function SimpleRoundTo2Digits(Value: Currency): Currency;

No banker rounding into two digits after the decimal point
- #.##51 will round to #.##+0.01 and #.##50 will be truncated to #.##
- implementation will use fast Int64 math to avoid any precision loss due to temporary floating-point conversion


1.5.341. SimpleRoundTo2DigitsCurr64

procedure SimpleRoundTo2DigitsCurr64(var Value: Int64);

Simple, no banker rounding of a Currency value, stored as Int64, to only 2 digits
- #.##51 will round to #.##+0.01 and #.##50 will be truncated to #.##
- implementation will use fast Int64 math to avoid any precision loss due to temporary floating-point conversion


1.5.342. SortDynArray128

function SortDynArray128(const A, B): integer;

Compare two "array of THash128" 128-bit elements


1.5.343. SortDynArray256

function SortDynArray256(const A, B): integer;

Compare two "array of THash256" 256-bit elements


1.5.344. SortDynArray512

function SortDynArray512(const A, B): integer;

Compare two "array of THash512" 512-bit elements


1.5.345. SortDynArrayAnsiString

function SortDynArrayAnsiString(const A, B): integer;

Compare two "array of AnsiString" elements, with case sensitivity
- on Intel/AMD will use efficient i386/x86_64 assembly using length
- on other CPU, will redirect to inlined StrComp() using #0 trailing char


1.5.346. SortDynArrayBoolean

function SortDynArrayBoolean(const A, B): integer;

Compare two "array of boolean" 8-bit elements


1.5.347. SortDynArrayByte

function SortDynArrayByte(const A, B): integer;

Compare two "array of byte" 8-bit elements


1.5.348. SortDynArrayCardinal

function SortDynArrayCardinal(const A, B): integer;

Compare two "array of cardinal" 32-bit elements


1.5.349. SortDynArrayDouble

function SortDynArrayDouble(const A, B): integer;

Compare two "array of double" 64-bit elements


1.5.350. SortDynArrayExtended

function SortDynArrayExtended(const A, B): integer;

Compare two "array of TSynExtended" 64/80-bit elements


1.5.351. SortDynArrayInt64

function SortDynArrayInt64(const A, B): integer;

Compare two "array of Int64" or "array of Currency" 64-bit elements


1.5.352. SortDynArrayInteger

function SortDynArrayInteger(const A, B): integer;

Compare two "array of integer" 32-bit elements


1.5.353. SortDynArrayPointer

function SortDynArrayPointer(const A, B): integer;

Compare two "array of TObject/pointer" elements


1.5.354. SortDynArrayPUtf8Char

function SortDynArrayPUtf8Char(const A, B): integer;

Compare two "array of PUtf8Char/PAnsiChar" elements, with case sensitivity


1.5.355. SortDynArrayQWord

function SortDynArrayQWord(const A, B): integer;

Compare two "array of QWord" 64-bit elements
- note that QWord(A)>QWord(B) is wrong on older versions of Delphi, so you should better use this function or CompareQWord() to properly compare two QWord values over CPUX86


1.5.356. SortDynArrayShortint

function SortDynArrayShortint(const A, B): integer;

Compare two "array of shortint" 8-bit elements


1.5.357. SortDynArrayShortString

function SortDynArrayShortString(const A, B): integer;

Compare two "array of shortstring" elements, with case sensitivity


1.5.358. SortDynArraySingle

function SortDynArraySingle(const A, B): integer;

Compare two "array of single" 32-bit elements


1.5.359. SortDynArraySmallint

function SortDynArraySmallint(const A, B): integer;

Compare two "array of smallint" 16-bit elements


1.5.360. SortDynArrayString

function SortDynArrayString(const A, B): integer;

Compare two "array of RTL string" elements, with case sensitivity
- the expected string type is the RTL string


1.5.361. SortDynArrayUnicodeString

function SortDynArrayUnicodeString(const A, B): integer;

Compare two "array of WideString/UnicodeString" elements, with case sensitivity


1.5.362. SortDynArrayVariant

function SortDynArrayVariant(const A, B): integer;

Compare two "array of variant" elements, with case sensitivity
- just a wrapper around SortDynArrayVariantComp(A,B,false)


1.5.363. SortDynArrayVariantI

function SortDynArrayVariantI(const A, B): integer;

Compare two "array of variant" elements, with no case sensitivity
- just a wrapper around SortDynArrayVariantComp(A,B,true)


1.5.364. SortDynArrayWord

function SortDynArrayWord(const A, B): integer;

Compare two "array of word" 16-bit elements


1.5.365. SortMatch

function SortMatch(CompareResult: integer; CompareOperator: TCompareOperator): boolean;

Fast search if a comparison function result (<0,0,>0) match an operator


1.5.366. Split

function Split(const Str, SepStr: RawUtf8; StartPos: PtrInt = 1): RawUtf8; overload;

Returns the left part of a RawUtf8 string, according to SepStr separator
- if SepStr is found, returns Str first chars until (and excluding) SepStr
- if SepStr is not found, returns Str


1.5.367. StrCntAdd

procedure StrCntAdd(var refcnt: TStrCnt; increment: TStrCnt);

Low-level string reference counter process


1.5.368. StrCntDecFree

function StrCntDecFree(var refcnt: TStrCnt): boolean;

Low-level string reference counter unprocess
- caller should have tested that refcnt>=0
- returns true if the managed variable should be released (i.e. refcnt was 1)


1.5.369. StrComp

function StrComp(Str1, Str2: pointer): PtrInt;

Buffer-overflow safe version of StrComp(), to be used with PUtf8Char/PAnsiChar


1.5.370. StrCompW

function StrCompW(Str1, Str2: PWideChar): PtrInt;

Our fast version of StrComp(), to be used with PWideChar


1.5.371. StrInt32

function StrInt32(P: PAnsiChar; val: PtrInt): PAnsiChar;

Internal fast integer val to text conversion
- expect the last available temporary char position in P
- return the last written char position (write in reverse order in P^)
- typical use:

function Int32ToUtf8(Value: PtrInt): RawUtf8;
var
  tmp: array[0..23] of AnsiChar;
  P: PAnsiChar;
begin
  P := StrInt32(@tmp[23],Value);
  SetString(result,P,@tmp[23]-P);
end;

- convert the input value as PtrInt, so work with Int64 on 64-bit CPUs
- not to be called directly: use IntToStr() or Int32ToUtf8() instead


1.5.372. StrInt64

function StrInt64(P: PAnsiChar; const val: Int64): PAnsiChar;

Internal fast Int64 val to text conversion
- same calling convention as with StrInt32() above


1.5.373. StrLenSafe

function StrLenSafe(S: pointer): PtrInt;

Simple version of StrLen(), but which will never read beyond the string
- this version won't access the memory beyond the string, so may be preferred e.g. with valgrid
- SSE2 StrLen() versions would never read outside a memory page boundary, so are safe to use in practice, but may read outside the string buffer itself, so may not please paranoid tools like valgrid


1.5.374. StrLenW

function StrLenW(S: PWideChar): PtrInt;

Our fast version of StrLen(), to be used with PWideChar


1.5.375. StrUInt32

function StrUInt32(P: PAnsiChar; val: PtrUInt): PAnsiChar;

Internal fast unsigned integer val to text conversion
- expect the last available temporary char position in P
- return the last written char position (write in reverse order in P^)
- convert the input value as PtrUInt, so work with QWord on 64-bit CPUs


1.5.376. StrUInt64

function StrUInt64(P: PAnsiChar; const val: QWord): PAnsiChar;

Internal fast unsigned Int64 val to text conversion
- same calling convention as with StrInt32() above


1.5.377. SynLZcompress1

function SynLZcompress1(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;

Raw SynLZ compression algorithm
- includes optimized x86/x64 asm version on Intel/AMD
- just redirects to SynLZcompress1pas on other CPUs
- note that SynLZ is not very good at compressing a lot of zeros: it excels with somewhat already pre-encoded data like text, JSON or our mormot.core.data binary serialization


1.5.378. SynLZcompress1pas

function SynLZcompress1pas(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;

Raw SynLZ compression algorithm implemented in pascal
- you should rather call SynLZcompress1() which is likely to be much faster


1.5.379. SynLZcompressdestlen

function SynLZcompressdestlen(in_len: integer): integer;

Get maximum possible (worse) SynLZ compressed size


1.5.380. SynLZdecompress1

function SynLZdecompress1(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;

Raw SynLZ decompression algorithm
- includes optimized x86/x64 asm version on Intel/AMD
- just redirects to SynLZcompress1pas on other CPUs


1.5.381. SynLZdecompress1partial

function SynLZdecompress1partial(src: PAnsiChar; size: integer; dst: PAnsiChar; maxDst: integer): integer;

SynLZ decompression algorithm with memory boundaries check
- this function is slower, but will allow to uncompress only the start of the content (e.g. to read some metadata header)
- it will also check for dst buffer overflow, so will be more secure than other functions, which expect the content to be verified (e.g. via CRC)


1.5.382. SynLZdecompress1pas

function SynLZdecompress1pas(src: PAnsiChar; size: integer; dst: PAnsiChar): integer;

Raw SynLZ decompression algorithm implemented in pascal
- you should rather call SynLZdecompress1() which is likely to be much faster


1.5.383. SynLZdecompressdestlen

function SynLZdecompressdestlen(in_p: PAnsiChar): integer;

Get exact uncompressed size from SynLZ-compressed buffer (to reserve memory, e.g.)


1.5.384. TInt64DynArrayFrom

function TInt64DynArrayFrom(const Values: TIntegerDynArray): TInt64DynArray;

Quick helper to initialize a dynamic array of 64-bit integers from 32-bit values
- see also FromI64() for 64-bit signed integer values input


1.5.385. TIntegerDynArrayFrom

function TIntegerDynArrayFrom(const Values: array of integer): TIntegerDynArray;

Quick helper to initialize a dynamic array of integer from some constants
- can be used e.g. as:

 MyArray := TIntegerDynArrayFrom([1,2,3]);

- see also FromI32()


1.5.386. TIntegerDynArrayFrom64

function TIntegerDynArrayFrom64(const Values: TInt64DynArray; raiseExceptionOnOverflow: boolean = true): TIntegerDynArray;

Quick helper to initialize a dynamic array of integer from 64-bit integers
- will raise an Exception if any Value[] can not fit into 32-bit, unless raiseExceptionOnOverflow is FALSE and the returned array slot is filled with maxInt/minInt


1.5.387. ToCardinal

function ToCardinal(const text: RawUtf8; out value: cardinal; minimal: cardinal = 0): boolean;

Get the unsigned 32-bit cardinal value stored in a RawUtf8 string
- returns TRUE if the supplied text was successfully converted into a cardinal


1.5.388. ToDouble

function ToDouble(const text: RawUtf8; out value: double): boolean;

Get a 64-bit floating-point value stored in a RawUtf8 string
- returns TRUE if the supplied text was successfully converted into a double


1.5.389. ToHumanHex

procedure ToHumanHex(var result: RawUtf8; bin: PByteArray; len: PtrInt);

Convert a binary into its human-friendly per-byte hexadecimal lowercase text
- returns e.g. '12:50:b6:1e:c6:aa', i.e. the DN/MAC format
- used e.g. in mormot.lib.openssl11 and mormot.net.sock


1.5.390. ToHumanHexReverse

procedure ToHumanHexReverse(var result: RawUtf8; bin: PByteArray; len: PtrInt);

Convert a binary into its human-friendly hexadecimal in reverse order


1.5.391. ToInt64

function ToInt64(const text: RawUtf8; out value: Int64): boolean;

Get the signed 64-bit integer value stored in a RawUtf8 string
- returns TRUE if the supplied text was successfully converted into an Int64


1.5.392. ToInteger

function ToInteger(const text: RawUtf8; out value: integer): boolean;

Get the signed 32-bit integer value stored in a RawUtf8 string
- returns TRUE if the supplied text was successfully converted into an integer


1.5.393. ToText

function ToText(C: TClass): RawUtf8; overload;

Just a wrapper around ClassToText() to avoid a string conversion


1.5.394. TQWordDynArrayFrom

function TQWordDynArrayFrom(const Values: TCardinalDynArray): TQWordDynArray;

Quick helper to initialize a dynamic array of 64-bit integers from 32-bit values
- see also FromU64() for 64-bit unsigned integer values input


1.5.395. Trim

function Trim(const S: RawUtf8): RawUtf8;

Fast dedicated RawUtf8 version of Trim()
- in the middle of UI code, consider using TrimU() which won't have name collision ambiguity as with SysUtils' homonymous function


1.5.396. TrimCopy

procedure TrimCopy(const S: RawUtf8; start, count: PtrInt; var result: RawUtf8);

Single-allocation (therefore faster) alternative to Trim(copy())


1.5.397. TrimSelf

procedure TrimSelf(var S: RawUtf8);

Fast dedicated RawUtf8 version of s := Trim(s)


1.5.398. TrimU

function TrimU(const S: RawUtf8): RawUtf8;

Fast dedicated RawUtf8 version of Trim()
- should be used for RawUtf8 instead of SysUtils' Trim() which is ambiguous with the main String/UnicodeString type of Delphi 2009+
- in mORMot 1.18, there was a Trim() function but it was confusing


1.5.399. TruncTo2Digits

function TruncTo2Digits(Value: currency): currency;

Truncate a currency value to only 2 digits
- implementation will use fast Int64 math to avoid any precision loss due to temporary floating-point conversion


1.5.400. TruncTo2Digits64

function TruncTo2Digits64(Value: Int64): Int64;

Truncate a Currency value, stored as Int64, to only 2 digits
- implementation will use fast Int64 math to avoid any precision loss due to temporary floating-point conversion


1.5.401. TruncTo2DigitsCurr64

procedure TruncTo2DigitsCurr64(var Value: Int64);

Truncate a currency value, stored as Int64, to only 2 digits
- implementation will use fast Int64 math to avoid any precision loss due to temporary floating-point conversion


1.5.402. TwoDigits

function TwoDigits(const d: double): TShort23;

No banker rounding into text, with two digits after the decimal point
- #.##51 will round to #.##+0.01 and #.##50 will be truncated to #.##
- this function will only allow 2 digits in the returned text


1.5.403. UniqueRawUtf8

function UniqueRawUtf8(var u: RawUtf8): pointer;

Equivalence to @u[1] expression to ensure a RawUtf8 variable is unique
- will ensure that the string refcount is 1, and return a pointer to the text
- under FPC, @u[1] does not call UniqueString() as it does with Delphi
- if u is a constant (refcount=-1), will allocate a temporary copy in heap


1.5.404. UnSetBit

procedure UnSetBit(var Bits; aIndex: PtrInt);

Unset/clear a particular bit into a bit array
- this function can't be inlined, whereas UnSetBitPtr() function can


1.5.405. UnSetBit64

procedure UnSetBit64(var Bits: Int64; aIndex: PtrInt);

Unset/clear a particular bit into a 64-bit integer bits (max aIndex is 63)


1.5.406. UnSetBitPtr

procedure UnSetBitPtr(Bits: pointer; aIndex: PtrInt);

Unset/clear a particular bit into a bit array
- UnSetBit() can't be inlined, whereas this pointer-oriented function can


1.5.407. Utf8ToInt64

function Utf8ToInt64(const text: RawUtf8; const default: Int64 = 0): Int64;

Get the signed 64-bit integer value stored in a RawUtf8 string
- returns the default value if the supplied text was not successfully converted into an Int64


1.5.408. Utf8ToInteger

function Utf8ToInteger(const value: RawUtf8; min, max: PtrInt; default: PtrInt = 0): PtrInt; overload;

Get and check range of a signed 32-bit integer stored in a RawUtf8 string
- we use the PtrInt result type, even if expected to be 32-bit, to use native CPU register size (don't want any 32-bit overflow here)


1.5.409. Utf8ToInteger

function Utf8ToInteger(const value: RawUtf8; Default: PtrInt = 0): PtrInt; overload;

Get the signed 32-bit integer value stored in a RawUtf8 string
- we use the PtrInt result type, even if expected to be 32-bit, to use native CPU register size (don't want any 32-bit overflow here)


1.5.410. VarClearAndSetType

procedure VarClearAndSetType(var v: variant; vtype: integer);

Overloaded function which can be properly inlined to clear a variant


1.5.411. VarDataFromVariant

function VarDataFromVariant(const Value: variant): PVarData;

Get the root PVarData of a variant, redirecting any varByRef
- if result^.VPointer=nil, returns varEmpty


1.5.412. VarDataIsEmptyOrNull

function VarDataIsEmptyOrNull(VarData: pointer): boolean;

Same as VarIsEmpty(PVariant(V)^) or VarIsNull(PVariant(V)^), but faster
- we also discovered some issues with FPC's Variants unit, so this function may be used even in end-user cross-compiler code


1.5.413. VariantCompSimple

function VariantCompSimple(const A, B: variant): integer;

Basic default case-sensitive variant comparison function
- try as VariantToInt64/VariantToDouble, then RTL VarCompareValue()


1.5.414. VariantStringToUtf8

procedure VariantStringToUtf8(const V: Variant; var result: RawUtf8); overload;

Convert a Variant varString value into RawUtf8 encoded String
- works as the exact reverse of RawUtf8ToVariant() function
- non varString variants (e.g. UnicodeString, WideString, numbers, empty and null) will be returned as ''
- use VariantToUtf8() instead if you need to convert numbers or other strings
- use VariantSaveJson() instead if you need a conversion to JSON with custom parameters


1.5.415. VariantStringToUtf8

function VariantStringToUtf8(const V: Variant): RawUtf8; overload;

Convert Variant string values into RawUtf8 encoded String
- works as the exact reverse of RawUtf8ToVariant() function
- non varString variants (e.g. UnicodeString, WideString, numbers, empty and null) will be returned as ''


1.5.416. VariantToBoolean

function VariantToBoolean(const V: Variant; var Value: boolean): boolean;

Convert any numerical Variant into a boolean value
- text content will return true after case-sensitive 'true' comparison


1.5.417. VariantToCurrency

function VariantToCurrency(const V: Variant; var Value: currency): boolean;

Convert any numerical Variant into a fixed decimals floating point value


1.5.418. VariantToDouble

function VariantToDouble(const V: Variant; var Value: double): boolean;

Convert any numerical Variant into a floating point value


1.5.419. VariantToDoubleDef

function VariantToDoubleDef(const V: Variant; const default: double = 0): double;

Convert any numerical Variant into a floating point value


1.5.420. VariantToInt64

function VariantToInt64(const V: Variant; var Value: Int64): boolean;

Convert any numerical Variant into a 64-bit integer
- it will expect true numerical Variant and won't convert any string nor floating-pointer Variant, which will return FALSE and won't change the Value variable content


1.5.421. VariantToInt64Def

function VariantToInt64Def(const V: Variant; DefaultValue: Int64): Int64;

Convert any numerical Variant into a 64-bit integer
- it will expect true numerical Variant and won't convert any string nor floating-pointer Variant, which will return the supplied DefaultValue


1.5.422. VariantToInteger

function VariantToInteger(const V: Variant; var Value: integer): boolean;

Convert any numerical Variant into a 32-bit integer
- it will expect true numerical Variant and won't convert any string nor floating-pointer Variant, which will return FALSE and won't change the Value variable content


1.5.423. VariantToIntegerDef

function VariantToIntegerDef(const V: Variant; DefaultValue: integer): integer; overload;

Convert any numerical Variant into an integer
- it will expect true numerical Variant and won't convert any string nor floating-pointer Variant, which will return the supplied DefaultValue


1.5.424. VariantToRawByteString

procedure VariantToRawByteString(const Value: variant; var Dest: RawByteString);

Convert back a RawByteString from a variant
- the supplied variant should have been created via a RawByteStringToVariant() function call


1.5.425. VarIsEmptyOrNull

function VarIsEmptyOrNull(const V: Variant): boolean;

Same as VarIsEmpty(V) or VarIsNull(V), but faster
- we also discovered some issues with FPC's Variants unit, so this function may be used even in end-user cross-compiler code


1.5.426. WordScanIndex

function WordScanIndex(P: PWordArray; Count: PtrInt; Value: word): PtrInt;

Fast search of an unsigned Word value position in a Word array
- Count is the number of Word entries in P^
- return index of P^[index]=Value, -1 if Value was not found
- is implemented with SSE2 asm on i386 and x86_64


1.5.427. XorEntropy

procedure XorEntropy(var e: THash512Rec);

Retrieve 512-bit of entropy, from system time and current execution state
- entropy is gathered over several sources like RTL Now(), CreateGuid(), current gsl_rng_taus2 Lecuyer state, and RdRand32/Rdtsc low-level Intel opcodes
- the resulting output is to be hashed - e.g. with DefaultHasher128
- execution is fast, but not enough as unique seed for a cryptographic PRNG: TAesPrng.GetEntropy will call it as one of its entropy sources, in addition to system-retrieved randomness from mormot.core.os.pas' XorOSEntropy()


1.5.428. XorMemory

procedure XorMemory(Dest, Source: PByteArray; size: PtrInt); overload;

Logical XOR of two memory buffers
- will perform on all buffer bytes:

 Dest[i] := Dest[i] xor Source[i];

1.5.429. XorMemory

procedure XorMemory(Dest, Source1, Source2: PByteArray; size: PtrInt); overload;

Logical XOR of two memory buffers into a third
- will perform on all buffer bytes:

 Dest[i] := Source1[i] xor Source2[i];

1.5.430. xxHash32

function xxHash32(crc: cardinal; P: PAnsiChar; len: cardinal): cardinal;

Perform very fast xxHash hashing in 32-bit mode
- will use optimized asm for x86/x64, or a pascal version on other CPUs


1.5.431. xxHash32Mixup

function xxHash32Mixup(crc: cardinal): cardinal;

Shuffle a 32-bit value using the last stage of xxHash32 algorithm
- is a cascade of binary shifts and multiplications by prime numbers
- see also (c * KNUTH_HASH32_MUL) shr (32 - bits) as weaker alternative


1.5.432. YearToPChar

procedure YearToPChar(Y: PtrUInt; P: PUtf8Char);

Add the 4 digits of integer Y to P^ as '0000'..'9999'


1.6. Variables implemented in the mormot.core.base unit

1.6.1. adler32

adler32: THasher;

Compute ADLER32 checksum on the supplied buffer
- is only available if mormot.lib.z.pas unit is included in the project


1.6.2. ClassUnit

ClassUnit: function(C: TClass): PShortString;

Retrieve the unit name where a given class is implemented
- is implemented in mormot.core.rtti.pas; so may be nil otherwise
- is needed since Delphi 7-2009 do not define TObject.UnitName (because there is no such information available in RTTI)


1.6.3. CompareMemFixed

CompareMemFixed: function(P1, P2: pointer; Length: PtrInt): boolean = CompareMem;

A CompareMem()-like function designed for small and fixed-sized content
- here, Length is expected to be a constant value - typically from SizeOf() - so that inlining has better performance than calling the CompareMem() function


1.6.4. CpuAvx10

CpuAvx10: TIntelAvx10Features;

The detected AVX10 Converged Vector ISA features
- only set if cfAVX10 is part of CpuFeatures


1.6.5. CpuFeatures

CpuFeatures: TIntelCpuFeatures;

The available Intel/AMD CPU features, as recognized at program startup
- on LINUX, consider CpuInfoArm or the textual CpuInfoFeatures from mormot.core.os.pas


1.6.6. crc32

crc32: THasher = crc32fast;

Compute CRC32 checksum on the supplied buffer
- mormot.lib.z.pas will replace with its official (may be faster) version


1.6.7. crc32c

crc32c: THasher = crc32cfast;

Compute CRC32C checksum on the supplied buffer
- result is not compatible with zlib's crc32() - Intel/SCSI CRC32C has not same polynom - but will use the fastest mean available, e.g. SSE 4.2 or ARMv8, achieve up to 16GB/s with the optimized implementation from mormot.crypt.core
- you should use this function instead of crc32cfast() or crc32csse42()


1.6.8. crc32cBy4

crc32cBy4: function(crc, value: cardinal): cardinal = crc32cBy4fast;

Compute CRC32C checksum on one 32-bit unsigned integer
- can be used instead of crc32c() for inlined process during data acquisition
- doesn't make "crc := not crc" before and after the computation: caller has to start with "crc := cardinal(not 0)" and make "crc := not crc" at the end, to compute the very same hash value than regular crc32c()
- this variable will use the fastest mean available, e.g. SSE 4.2 or ARMv8


1.6.9. crc32ctab

crc32ctab: TCrc32tab;

8KB tables used by crc32cfast() function
- created with a polynom diverse from zlib's crc32() algorithm, but compatible with SSE 4.2 crc32 instruction
- tables content is created from code in initialization section below
- will also be used internally by SymmetricEncrypt and TSynUniqueIdentifierGenerator as 1KB master/reference key tables


1.6.10. crc32tab

crc32tab: TCrc32tab;

8KB tables used by crc32fast() function


1.6.11. crcblock

crcblock: procedure(crc128, data128: PBlock128) = crcblockfast;

Compute a proprietary 128-bit CRC of a 128-bit binary buffer
- apply four crc32c() calls on the 128-bit input chunk, into a 128-bit crc
- its output won't match crc128c() value, which works on 8-bit input
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- is used e.g. by mormot.crypt.core's TAesCfc/TAesOfc/TAesCtc to check for data integrity


1.6.12. crcblocks

crcblocks: procedure(crc128, data128: PBlock128; count: integer) = crcblocksfast;

Compute a proprietary 128-bit CRC of 128-bit binary buffers
- apply four crc32c() calls on the 128-bit input chunks, into a 128-bit crc
- its output won't match crc128c() value, which works on 8-bit input
- will use SSE 4.2 or ARMv8 hardware accelerated instruction, if available
- is used e.g. by crc32c128 or mormot.crypt.ecc's TEcdheProtocol.ComputeMAC for macCrc128c or TAesAbstractAead.MacCheckError


1.6.13. DefaultHasher

DefaultHasher: THasher = xxHash32;

The 32-bit default hasher used by TDynArrayHashed
- set to crc32csse42() if SSE4.2 or ARMv8 are available on this CPU, or fallback to xxHash32() which is faster than crc32cfast() e.g. on ARM
- mormot.crypt.core may assign safer and faster AesNiHash32() if available
- so the hash value may change on another computer or after program restart


1.6.14. DefaultHasher128

DefaultHasher128: THasher128 = crc32c128;

A 128-bit hasher function
- crc32c128() by default, but mormot.crypt.core may assign AesNiHash128()
- so the hash value may change on another computer or after program restart


1.6.15. DefaultHasher64

DefaultHasher64: THasher64 = crc32cTwice;

A 64-bit hasher function
- crc32cTwice() by default, but mormot.crypt.core may assign AesNiHash64()
- so the hash value may change on another computer or after program restart


1.6.16. DOUBLE_PRECISION

DOUBLE_PRECISION: integer = 15;

Best possible precision when rendering a "double" kind of float
- can be used as parameter for ExtendedToShort/ExtendedToStr
- is defined as a var, so that you may be able to override the default settings, for the whole process


1.6.17. EXTENDED_PRECISION

EXTENDED_PRECISION: integer = 18;

Best possible precision when rendering a "extended" kind of float
- can be used as parameter for ExtendedToShort/ExtendedToStr
- is defined as a var, so that you may be able to override the default settings, for the whole process


1.6.18. GetBitsCountPtrInt

GetBitsCountPtrInt: function(value: PtrInt): PtrInt = GetBitsCountPas;

Compute how many bits are set in a given pointer-sized integer
- the PopCnt() intrinsic under FPC doesn't have any fallback on older CPUs, and default implementation is 5 times slower than our GetBitsCountPas() on x64
- this redirected function will use fast SSE4.2 "popcnt" opcode, if available


1.6.19. InterningHasher

InterningHasher: THasher = xxHash32;

The 32-bit hash function used by TRawUtf8Interning
- set to crc32csse42() if SSE4.2 or ARMv8 are available on this CPU, or fallback to xxHash32() which performs better than crc32cfast()
- mormot.crypt.core may assign safer and faster AesNiHash32() if available
- so the hash value may change on another computer or after program restart


1.6.20. Null

Null: variant absolute NullVarData;

A slightly faster alternative to Variants.Null function


1.6.21. SINGLE_PRECISION

SINGLE_PRECISION: integer = 8;

Best possible precision when rendering a "single" kind of float
- can be used as parameter for ExtendedToShort/ExtendedToStr
- is defined as a var, so that you may be able to override the default settings, for the whole process


1.6.22. SortDynArrayRawByteString

SortDynArrayRawByteString: TDynArraySortCompare = SortDynArrayAnsiString;

Compare two "array of RawByteString" elements, with case sensitivity
- can't use StrComp() or similar functions since RawByteString may contain #0
- on Intel/AMD, the more efficient SortDynArrayAnsiString asm is used instead


1.6.23. SortDynArrayVariantComp

SortDynArrayVariantComp: function( const A, B: TVarData; caseInsensitive: boolean): integer;

Compare two variant/TVarData values, with or without case sensitivity
- this unit registers the basic VariantCompSimple() case-sensitive comparer
- mormot.core.variants will assign the much better FastVarDataComp()
- called e.g. by SortDynArrayVariant/SortDynArrayVariantI functions


1.6.24. StrLen

StrLen: function(S: pointer): PtrInt = StrLenSafe;

Our fast version of StrLen(), to be used with PUtf8Char/PAnsiChar
- under x86, will detect SSE2 and use it if available, reaching e.g. 37.5 GB/s on a Core i5-13500 under Linux x86_64
- on ARM/AARCH64 POSIX, mormot.core.os would redirect to optimized libc


1.6.25. TwoDigitLookupW

TwoDigitLookupW: packed[0..99] of word absolute TwoDigitLookup;

Fast lookup table for converting any decimal number from 0 to 99 into their ASCII equivalence


1.6.26. VarFalse

VarFalse: variant absolute FalseVarData;

A slightly faster alternative to false constant when assigned to a variant


1.6.27. VariantClearSeveral

VariantClearSeveral: procedure(V: PVarData; n: integer);

Efficient finalization of successive variant items from a (dynamic) array
- this unit will include a basic version calling VarClear()
- mormot.core.variants will assign a more efficient implementation


1.6.28. VarTrue

VarTrue: variant absolute TrueVarData;

A slightly faster alternative to true constant when assigned to a variant