[AccessD] Function vs Sub

jwcolby jwcolby at colbyconsulting.com
Tue Feb 24 15:22:51 CST 2009


I would think that the subject gets deep rather quickly.  You have to understand where the various 
local variables (inside of the function) are stored and how they are passed back.

My understanding is that complex data types such as classes, strings etc are stored on the heap 
(global to the program, outside of the function) but that simple data types are stored on the stack 
(local to or "inside" of the function).  Is the return code copying the data itself into a storage 
location or simply returning a pointer to the data.  With complex data types it is almost certainly 
a pointer to a location on the heap.

With local variables however, if it is a pointer to the data, then "simple variables" would be 
getting a pointer to a location to the stack, and the stack is SUPPOSED to be popped as the function 
exits.  That would APPEAR to mean that a pointer is not possible with a local simple variable, and 
so a copy of the data would be required.  Now... one OPCODE maybe, but how about the data (a float 
for instance is 80 bytes stored in a register) being copied to a memory location.  It may in fact 
just be one "op code" to do that but there is at least some overhead to pack / unpack that 80 byte 
real into 32 / 64 / 128 bit memory locations.

Again, I do not understand the inner workings of the interpreter, but common sense says there is 
probably some overhead.

John W. Colby
www.ColbyConsulting.com


Stuart McLachlan wrote:
> Don't know about VBA, but according to Bob Zale, the overhead in the 
> PowerBasic compiler is exactly one Opcode.  :-)
> 



More information about the AccessD mailing list