bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GMP compiled under MacOS/C++ wrap


From: Hans Aberg
Subject: Re: GMP compiled under MacOS/C++ wrap
Date: Thu, 26 Apr 2001 11:08:43 +0200

At 08:20 +1000 2001/04/26, Kevin Ryde wrote:
>I mean the macos/configure and macos/Makefile.in etc.  (Bug reports
>direct to Kent about that, see macos/README.)

I did not use that; it is for MPW, and I do not use MPW.

>> In addition, I am now making a Flex/Bison parser, making it easy to test
>> the different arithmetic operations (calculator style).
>
>Have a look at demos/calc.y and calclex.l if you haven't already.
>Very minimal, but better than a poke in the eye with a burnt stick.
>:-)

Thank you for the reference.

>> It is not possible (by empirical experience) under C++ to return a
>> reference from a function and combine it with a proper memory management
>> (for example, exceptions will screw it up).
>
>Really?  Oh well.

One can take an example, say (assuming that the class "integer" has a field
"mpz_t value_;")
  inline integer operator+(const& x, const& y) {
    integer r; mpz_add(r.value_, x.value_, y.value_); return r;
  }
Here the problem is the "return r"; in reality, compilers will invoke the
copy constructor
  integer::integer(const integer& x) { mpz_init_set(value_, x.value_); }
In principle, the compiler could optimize it away, but in reality compilers
does not seem to do it.

>> Again, I think that this might be slow. So therefore I want the
>> __mpz_struct have all its data in the pointer, plus reserved space for the
>> count.
>
>Perhaps it'd work to tack an extra field on the end.  Then p->z is
>simply a type-safe cast.
>
>        struct mpz_with_refcnt {
>          mpz_t  z;
>          int    refcnt;
>        };

This is the traditional way I would want to avoid, because when used, one
will make a double dynamic allocation, first for the mpz_with_refcnt
structure, and second for the for the _mp_d field of the mpz_t structure. I
think this double allocation might be slow.

Also, I think that ref counts are hard to work with under C, so if one
variation should be tried, I would just put it in connection with the
gmp::integer class.

  Hans Aberg
                  * Email: Hans Aberg <mailto:address@hidden>
                  * Home Page: <http://www.matematik.su.se/~haberg/>
                  * AMS member listing: <http://www.ams.org/cml/>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]