From: Maarten Kronenburg (M.Kronenburg_at_[hidden])
Date: 2008-03-31 14:10:02
"Giovanni Piero Deretta" wrote in message
> On Mon, Mar 31, 2008 at 6:39 PM, Maarten Kronenburg
> > "Kevin Sopp" wrote in message > Hi Maarten,
> > >
> > > On Sun, Mar 30, 2008 at 10:13 PM, Maarten Kronenburg
> > > wrote:
> > >
> > > > Just for your info I designed another interface, see document
> > >
> > > I knew about your document after I searched the internet for ideas on
> > > how to design the interface of the mp_int class template.
> > >
> > > >
> > > > The root question here seems to be: do you use runtime
> > (virtual
> > > > functions) or compile time polymorphism (templates). My argument
> > that as
> > > > this class is so close to the hardware, and performance is so
> > important,
> > > > that runtime polymorphism will in this case provide the runtime
> > flexibility
> > > > needed.
> > >
> > > I never really understood why you chose this approach, it is really
> > > different from the rest of the standard library. I understand that
> > > achieve interoperability with the other integer types but this could
> > > be hardcoded once all integer types to be standardized are known.
> > > I think that interoperability of the integer types is a minor concern
> > > and as such should not govern the major design decision.
> > >
> > Interoperability is a major concern, because it is also available for
> > base type ints:
> > int x = -5;
> > unsigned int y = 10;
> > x -= y;
> > y -= x;
> > etc.
> You can easily make two multi precision integers or policies using
> different allocators interoperate:
> Int<signed, my_alloc> x = -5;
> Int<unsigned, your_alloc> y = 10;
> x -= y;
> y -= x;
> This can be almost trivially made to work, I think.
> In case of x + y, you just need to decide which combination of rhs and
> lhs policies to use.
Probably you would use conversion operators. But runtime polymorphism allows
basetype pointers to derived type objects, and still it works (through the
vtable). So runtime polymorphism can never be fully replaced by something
> > The STL is made with templates, and rightly so, because containers have
> > template parameters (e.g. what type they should contain). But this does
> > mean that other designs should be "templatized". Sometimes programmers
> > runtime polymorphism to achieve runtime flexibility, and in my opinion
> > integer class is an example.
> It is easy to add runtime polymorphism to static polymorphic desings.
> It is impossible to do it the other way.
This would mean changing the design. Let's do it right from the beginning.
In my opinion my design is the right one, but of course anyone is free to
> > > > In your design the algorithms will probably end up in headers
> > like the
> > > > STL), while my algorithms will end up in DLLs. In other words: my
> > design
> > > > considers the allocator and the traits as implementation details
> > (although
> > > > in my design it is possible to change the allocator dynamically),
> > your
> > > > design considers these as design parameters.
> > >
> > > The traits parameter is totally implementation defined. I included it
> > > because I wanted to give the user a way to customize some of the
> > > internal workings of the class, usually in C libraries this is done
> > > via macro definitions at compile time. Most users don't need to
> > > but if you're a poweruser with very large calculations you have at
> > > least a few knobs to finetune the internals. There was almost never a
> > > question in my mind about the allocator parameter. After all it would
> > > be strange not to have one for a class that will potentially allocate
> > > a large amount of memory.
> > In my opinion implementation parameters should be kept out of the
> > I agree about the allocator, this is why in my design I have added an
> > allocator, only it is set at runtime.
> If you use a scoped allocator (a-la alloca) as a template parameter, a
> decent compiler could completely optimize it away. It is very hard
> (although not impossible) to do the same if you have a runtime
Perhaps there are some developments with STL allocators that I don't know.
But after the optimization it still uses an allocator, right?
But I admit that an allocator in my design (with an allocated_integer) would
have to be set first at runtime, otherwise an error is generated. But users
that don't need another allocator, just use the base class integer, and
don't bother with any allocator.
In my design it is also possible to share allocators, as they are static.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk