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.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Introduction to 0/1 Knapsack Problem
Next Post: How Programmer Reads Your CV?