[mercury-users] Exceptions and unique modes

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Feb 23 11:38:46 AEDT 2001


On 22-Feb-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> On Thu, Feb 22, 2001 at 05:01:28PM +1100, Fergus Henderson wrote:
> > In particular, what would you do about code which tries to reuse the
> > storage for something with a `di' mode, e.g. by explicitly deallocating
> > it so that the allocator can reuse it to hold something that has a
> > different type?
>
> You would think that the best canditate for reuse of that memory is the
> next state.  Unfortunately it is not quite that easy as the following
> type indicates.
> 
> :- type t
>     --->    f(int)
>     ;       g(int, int).
> 
> No matter what you initialise this type to you need to make sure that
> you allocate 2 words so that you can possibly hold the g constructor at
> some later date.

That would be a bad idea in general, e.g. consider

	:- type t2
	     --->    f2(int)
	     ;       g2(int, int, int, int, int, int, int, int, int, int,
	     		int, int, int, int, int, int, int, int, int, int).

and suppose that 99% of all values of type `t' use f2/1 rather than g2/22.
Even for your type t, the cost of the extra space needed to allocate
two words rather than one for f/1 may outweigh any gains you get from
additional reuse.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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