Delphi built-in data types and their memory sizes

  

Though 64-bit support was released back in 2011 with Delphi XE2, sometimes I forget which data type are native size and which keep their size no matter the compiler bitness (wiktionary/wikipedia).
This post was motivated by via [WayBack] Having started with Delphi before the Cardinal type was available (Or has it always? I can’t remember.) I routinely declare 32 bit unsigned variables as… – Thomas Mueller (dummzeuch) – Google+
The most simple distinction is between Win32 and Win64, but there are more non-32 bit platforms, so these do not suffice any more:

[WayBack] 64-bit Windows Data Types Compared to 32-bit Windows Data Types – RAD Studio 10.2 Tokyo
[WayBack] 64-bit Windows Data Types Compared to 32-bit Windows Data Types – RAD Studio XE3 (yes, that did not get documented in XE2)

The easiest for me are the below tables that only got introduced with Delphi 10.2 Tokyo: [WayBack] Delphi Data Types for API Integration – RAD Studio.
I have bolded the ones that change size.

Integer Data Types

Type
Description
Pointer

Byte
8-bit unsigned integer
PByte

ShortInt
8-bit signed integer
PShortInt

Word
16-bit unsigned integer
PWord

SmallInt
16-bit signed integer
PSmallInt

Cardinal
32-bit unsigned integer
PCardinal

LongWord
32-bit unsigned integer (32-bit Windows, OSX32, 32-bit iOS, and Android platforms)
64-bit unsigned integer (64-bit iOS and 64-bit Linux platforms)
PLongWord

FixedUInt
32-bit unsigned integer
PFixedUInt

Integer
32-bit signed integer
PInteger

LongInt
32-bit signed integer (32-bit Windows, OSX32, 32-bit iOS, and Android platforms)
64-bit signed integer (64-bit iOS and 64-bit Linux platforms)
PLongint

FixedInt
32-bit signed integer
PFixedInt

UInt64
64-bit unsigned integer
PUInt64

Int64
64-bit signed integer
PInt64

NativeUInt
64-bit or 32-bit platform-dependent unsigned integer
PNativeUInt

NativeInt
64-bit or 32-bit platform-dependent signed integer
PNativeInt

Floating-point Data Types

Type
Description
Pointer
Record

Single
Single precision floating-point value (4 bytes)
PSingle
TSingleRec

Double
Double precision floating-point value (8 bytes)
PDouble
TDoubleRec

Extended
Extended precision floating-point value (10 bytes on Win32, but 8 bytes on Win64)
See page about multi-device applications.
PExtended
TExtended80Rec

Real
Alias of Double
N/A
N/A

Earlier on, the

Delphi XE2 documentation added a section describing the platform bitness effects in [WayBack] Simple Types (Delphi) – RAD Studio XE2
Delphi XE8 documentation added more information for 64-bit iOS in [WayBack] Simple Types (Delphi) – RAD Studio XE8
Delphi 10.2 Tokyo documentation added more information on other 64-bit POSIX platform in [WayBack] Simple Types (Delphi) – RAD Studio 10.2 Tokyo

Platform-dependent integer types

Type
Platform
Range
Format
Alias

NativeInt
32-bit platforms
-2147483648..2147483647
(-231..2^31-1)
Signed 32-bit
Integer

64-bit platforms
-9223372036854775808..9223372036854775807
(-263..263-1)
Signed 64-bit
Int64

NativeUInt
32-bit platforms
0..4294967295
(0..232-1)
Unsigned 32-bit
Cardinal

64-bit platforms
0..18446744073709551615
(0..264-1)
Unsigned 64-bit
UInt64

LongInt
32-bit platforms and 64-bit Windows platforms
-2147483648..2147483647
(-231..231-1)
Signed 32-bit
Integer

64-bit POSIX platforms include iOS and Linux
-9223372036854775808..9223372036854775807
(-263..263-1)
Signed 64-bit
Int64

LongWord
32-bit platforms and 64-bit Windows platforms
0..4294967295
(0..232-1)
Unsigned 32-bit
Cardinal

64-bit POSIX platforms include iOS and Linux
0..18446744073709551615
(0..264-1)
Unsigned 64-bit
UInt64

Note: 32-bit platforms include 32-bit Windows, 32-bit macOS, 32-bit iOS, iOS Simulator and Android.

Platform-Independent Integer Types
Platform-independent integer types always have the same size, regardless of what platform you use. Platform-independent integer types include ShortInt, SmallInt, LongInt, Integer, Int64, Byte, Word, LongWord, Cardinal, and UInt64.
Platform-independent integer types

Type
Range
Format
Alias

ShortInt
-128..127
Signed 8-bit
Int8

SmallInt
-32768..32767
Signed 16-bit
Int16

FixedInt
-2147483648..2147483647
Signed 32-bit
Int32

Integer
-2147483648..2147483647
Signed 32-bit
Int32

Int64
-9223372036854775808..9223372036854775807
(-263..263-1)
Signed 64-bit

Byte
0..255
Unsigned 8-bit
UInt8

Word
0..65535
Unsigned 16-bit
UInt16

FixedUInt
0..4294967295
Unsigned 32-bit
UInt32

Cardinal
0..4294967295
Unsigned 32-bit
UInt32

UInt64
0..18446744073709551615
(0..264-1)
Unsigned 64-bit

Thomas Mueller blogged about the Alias at [WayBack] Delphi LongWord is not always a 32 bit unsigned integer – twm’s blog (via[WayBack] Did you known that LongWord in Delphi is not (any longer) always a 32 bit unsigned integer? – Thomas Mueller (dummzeuch) – Google+) and I think he understood it backwards from what Embarcadero means:

NativeInt on 32-bit platforms is an alias of Integer (so it is Signed 32-bit)
NativeInt on 64-bit platforms is an alias of Int64 (so it is Signed 64-bit)

Some more fun links
For a lazy afternoon:

History

[WayBack] Delphi 2007: Simple Types
[WayBack] Delphi 2009: Simple Types

[WayBack] compiler construction – Why is creating a 64bit Delphi so hard? – Stack Overflow
[WayBack] Getting Ready for Delphi 64
[WayBack] The Oracle at Delphi: 64bit

[WayBack] The Oracle at Delphi: More x64 assembler fun-facts–new assembler directives
[WayBack] The Oracle at Delphi: x64 assembler fun-facts
[WayBack] The Oracle at Delphi: Delphi check-in log entries of the day:
[WayBack] The Oracle at Delphi: Divided and Confused
[WayBack] The Oracle at Delphi: It’s my stack frame, I don’t care about your stack frame!
[WayBack] The Oracle at Delphi: Delphi-Treff interview–In English

–jeroen

Comments are closed.