Re: Discovering variable types...
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 08/09/04
- Next message: Maarten Wiltink: "Re: Discovering variable types..."
- Previous message: Maarten Wiltink: "Re: Timer problem"
- In reply to:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Next in thread: Marco van de Voort: "Re: Discovering variable types..."
- Reply: Marco van de Voort: "Re: Discovering variable types..."
- Reply:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 9 Aug 2004 10:23:05 +0200
<not@any.adr> wrote in message
news:8ss9h0189sq7oodtbduck8udemjgprfqt6@4ax.com...
[...]
----+----*----+----*----+----*----+----*----+----*----+----*----+----*----+-
---*
> If you are using my mini memory manager, take a look at the SDK for
> the heap calls. You will find a function "HeapSize" which will tell
> you the size of any heap block owned by a pointer.
>
> var
> x : pointer;
> begin
> gemem(x,4096);
> writeln(sizeof(x)); // prints "4" on screen.
> Writeln(heapsize(hheap,x)); // prints "4096" on screen.
> end;
>
> This is because X is actually stored in the executable's memory space
> but the memory it points to is on the heap.
>
> Now a function similar to HeapSize that would tell me the memory space
> used by any given variable, from it's address, would be invaluable in
> several circumstances, not the least of which is sizing read and write
> operations.
You have a function similar to HeapSize: SizeOf. You could be asking for
SizeOf(p^) just as easily, if only p were a typed pointer. The catch is
that SizeOf is resolved ("generally", according to Bruce) at compile time.
That's in keeping with Pascal's philosophy as a strongly typed language.
You really are short-changing yourself by working against that when you
could be working with it, and making it work for you.
All those overloads may be source-intensive, but once you've written them
(once), there is no question anymore about the size of your parameter,
because it's now typed and SizeOf has somethingto work with. The parameter
is typed at the receiving end of the call, and the variable is typed at
the sending end, and the compiler matches them up for you. At run-time,
that information is thrown away because correctness is already guaranteed
and checking it again would just be useless overhead. You want to do it
at run-time so badly that you overlook the possibilities of doing it at
compile-time. And do it just once, for all time - not unlike writing
library code. The key is to work with the system, not against it, and make
the system work for you, not against you. Saves you from having to reinvent
the entire system every time.
Groetjes,
Maarten Wiltink
- Next message: Maarten Wiltink: "Re: Discovering variable types..."
- Previous message: Maarten Wiltink: "Re: Timer problem"
- In reply to:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Next in thread: Marco van de Voort: "Re: Discovering variable types..."
- Reply: Marco van de Voort: "Re: Discovering variable types..."
- Reply:(deleted message) not_at_any.adr: "Re: Discovering variable types..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|