The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,702 other followers

Delphi built-in data types and their memory sizes

Posted by jpluimers on 2019/08/21

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:

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

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 ShortIntSmallIntLongIntIntegerInt64ByteWordLongWordCardinal, 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:

–jeroen

5 Responses to “Delphi built-in data types and their memory sizes”

  1. thaddy said

    Of course the other powers of a negative value are also affected, here….
    negation after, power first. Power renders always a positive value.

  2. Thaddy said

    Hm, really?(-2^63..2^63-1) that gives it a downward range of one! It should be -(2^63).. 2^63 – 1;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: