[m-dev.] for review: stream I/O

Peter Ross petdr at miscrit.be
Tue Oct 3 02:35:27 AEDT 2000


On Mon, Oct 02, 2000 at 08:21:03AM -0700, Ralph Becket wrote:
> >From Peter Ross on 02/10/2000 15:59:44
> > However putback characters and line numbers are implemented at the C
> > level not at the Mercury level. This functionality is common to all
> > streams so it should be implemented at the Mercury level.
> 
> No no no!  This functionality is not common to all streams.  It's nice
> to have it on some input streams.  If a stream implementation doesn't
> supply putback_char//1 then use the stream wrapper type I posted a few
> messages ago.
> 
I didn't explain myself clearly enough.  The point is that if you want
to provide functionality like line numbers and infinite putback you need
somewhere to store this data and some efficient way of accessing it.
This should be implemented at the Mercury level not at the C level which
it is currently.  You are correct in that you should pay the cost for
this functionality if you don't need it.

> > I ported the Mission Critical lowlevel C solution to this problem and it
> > slows down the code by a factor of three for cat.m
> 
> I'm not sure I understand.  Did you implement putback_char//1 in C and
> get a slowdown or did you use a wrapper supplying putback_char//1 and
> get a slowdown?  If it's the latter case, then I'm not surprised:
> default and/or wrapper implementations should be expected to be more 
> costly than `native' implementations.  If it's the former then I'm very
> surprised since it should be no different than what we have in io.m now,
> so I'd be interested to learn what was causing the problem.
> 
Depending on what stream type you are using you select the native method
to call from a table of function pointers.  In otherwords the typeclass
approach written in C.  That extra level of indirection caused a factor
of three slowdown.

Pete
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list