Re: Discovering variable types...
From: Rob Kennedy (me3_at_privacy.net)
Date: 08/08/04
- Next message: Bjørge Sæther: "Re: Mix of stuff...."
- Previous message: Android Cat: "Re: Outlook Express"
- In reply to:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Next in thread: not_at_any.adr: "Re: Discovering variable types..."
- Reply:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 08 Aug 2004 14:29:57 -0500
not@any.adr wrote:
> The hitch is that Delphi doesn't store static variables (the ones we declare
> with Var statements on the heap. They're stored in a block at the top of the
> EXE file itself so that when you load the program you're actually loading the
> memory allocations for your variables from disk as well. If you notice the
> Delphi $M compiler directive lacks the memory allocation variable and now only
> does stack size. This is why.
If I were writing a compiler, I probably wouldn't allocate the global
variables on the heap, either. Why allocate them specially when you can
have the OS loader do it for you automatically? Even if I did allocate
them dynamically during startup, I certainly wouldn't allocate each
variable separately. I'd allocate one block large enough to hold them
all and then access them via offsets from the block's base address.
> The heapsize function only works for dynamic variables (from getmem or new)
> it's going to return an error with pointers to anything else. Sizeof only
> works with static variables and is going to return the size of the pointer (4)
> for dynamics.
SizeOf works on all variables. It returns the size of the variable. It
does not ever return the size of the memory allocated at the address
stored in that variable. SizeOf never inspects a variable's value.
> Interestingly SizeOf can delve into this memory area and get back the sizes of
> static variables by name. Looking at the code linked in by a sizeof call it
> appears to access some kind of table... but I haven't investigated it very far
> as yet.
SizeOf is a compile-time constant. It generates no code at all. The only
memory it delves into is the compiler's internal symbol table, which
doesn't exist at run time. That's how it can check the size based on the
name -- the compiler knows the name and the compiler evaluates SizeOf
right then and there.
-- Rob
- Next message: Bjørge Sæther: "Re: Mix of stuff...."
- Previous message: Android Cat: "Re: Outlook Express"
- In reply to:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Next in thread: not_at_any.adr: "Re: Discovering variable types..."
- Reply:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|