[mercury-users] Tagged datatypes and boxing

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 24 15:38:53 AEST 1999


On 23-Sep-1999, Ralph Becket <rbeck at microsoft.com> wrote:
> BUT!  Whoa!  I've just taken a second look at my code and it's using
> io__read_byte//1 which returns an io__result(int), which has *three*
> different
> constructors.  However, running this with memory-profiling doesn't reveal
> anything about this.

This is almost certainly due to the compiler's nifty deforestation
optimization.  Probably you compiled with -O6 --intermodule-optimization and
the compiler is inlining the call to io__read_byte and optimizing away the
memory allocation :-)

The interface to io__read_char (and hence also io__read_byte) was in fact
originally designed in the expectation that the compiler would eventually
perform the optimization that you mentioned.  Certainly a memory allocation
for every byte read would be rather unfortunate.  However it turns out that
deforestation, i.e. intermodule inlining plus optimization of constructions
followed by deconstructions or switches, is sufficient to avoid that.

> The only thing I get is from the output of
> report_stats/0 at the end of my main//0 which tells me I've used a few
> hundred kbytes

There are a few places in the Mercury standard library and runtime
where memory is allocated by C code rather than Mercury code;
these places don't show up in the memory profiling, unfortunately.
But io__read_byte is not one of these, so I suspect the
memory allocation is coming from somewhere else.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list