Optimal SizeOf Code Generated in Delphi 2007


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.

delphi-sizeof-test Optimal SizeOf Code Generated in Delphi 2007 assembly language beginner compiler delphi implementation interpreter / compiler profiler programming languages tools / utilities tricks

delphi-sizeof Optimal SizeOf Code Generated in Delphi 2007 assembly language beginner compiler delphi implementation interpreter / compiler profiler programming languages tools / utilities tricks

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.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
249 words
Last Post: Introduction to 0/1 Knapsack Problem
Next Post: How Programmer Reads Your CV?

The Permanent URL is: Optimal SizeOf Code Generated in Delphi 2007

Leave a Reply