Re: Discovering variable types...

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 08/09/04


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



Relevant Pages

  • Re: Print statement within If-Then block changes output!!!????
    ... assembler/compiler into producing it. ... ordinary variable because all of them are BCD floating point. ... POKE a value into memory, ... It sounds like they're supposed to compile. ...
    (comp.lang.fortran)
  • Re: Dual Core or Quad Core when running Quartus 7.1
    ... You're right about the importance of memory sub-system performance -- ... You have to tell Quartus that you want it to use more than one ... that compile time ...
    (comp.arch.fpga)
  • Re: 7.0 CPU and Memory Performance
    ... Since I was doing this on the same machine, with completely different builds (not simply a compile upgrade, but a full install), I figure it doesn't really matter what kind of machine it is, but just for grins, it is a Dual Opteron with 2GB of memory in it, compiled with the i386 confs. ... Now, I really don't know exactly what the ubench program is doing, but I think the description says that it is doing random integer and floating point operations for the CPU tests, and random memory allocation and copying for the memory test. ... I tried to run a PHP script using php 4.4.7 and got the following results: ... do the slower memory operations cause that difference in the real time it takes to run that script??? ...
    (freebsd-performance)
  • Re: Java and memory usage
    ... wasn't a large enough heap) and it then only used 10MB of memory. ... BTW do you mean you assigned the memory at compile time or runtime? ... It is running as a pathway server and I feed it the following ...
    (comp.sys.tandem)
  • Re: 7.0 CPU and Memory Performance
    ... Before doing this, I wanted to take some benchmarks to see how the scripts that I would run would fare between the two versions, and the results are somewhat confusing... ... Statically compile the 5.4 binary, and run the same binary on both ... Robert N M Watson ... Now, I really don't know exactly what the ubench program is doing, but I think the description says that it is doing random integer and floating point operations for the CPU tests, and random memory allocation and copying for the memory test. ...
    (freebsd-performance)