In Delphi, you can use SizeOf to get the size of a type or any variable. The SizeOf function returns the storage size, in bytes, of either a Variable or Type. The prototypes are listed below:
function SizeOf ( Variable : Any type ) : Integer; function SizeOf ( Type ) : Integer;
It is easy to guess that the Delphi compiler should be clever enough to determine the value of SizeOf during compilation time rather than run time. The following short program verifies this by printing sizeof-values of different variables by types or variables. Set a breakpoint and use Ctrl+Alt+D to invoke the disassembly window which shows the code compiled by Delphi.


From the above assembly code, we can see that it is very straightforward that the Delphi finds right away the correct size-of value for any given type or variables. The indexing of arrays (addressing) is omitted because it does not affect the size-of value.
Delphi / Object Pascal
- Delphi is 30 Years Old!
- Reviews of FixInsight - Delphi Static Code Analyser
- Lighting-fast Delphi 2007 Compiling Speed
- The Inline Keyword in Delphi
- Does Parallel.For in Delphi Actually Improve the Performance?
- Delphi TParallel Cleanup Needed
- Delphi Compiles Code to Linux 64-bit Server
- Integer Performance Comparisons of Delphi Win32, Win64 and Linux64 for Single/Multithreading Counting Prime Number
- How to Check If Running in 64-bit Windows Environment using Delphi?
- How to Check Debugger Present in Delphi?
- Delphi Static Code Analyser - FixInsight
- Optimal SizeOf Code Generated in Delphi 2007
–EOF (The Ultimate Computing & Technology Blog) —
242 wordsLast Post: Introduction to 0/1 Knapsack Problem
Next Post: How Programmer Reads Your CV?