help-gnu-emacs
[Top][All Lists]
Advanced

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

Why are Emacs integers so small?


From: Davin Pearson
Subject: Why are Emacs integers so small?
Date: Tue, 6 May 2008 01:00:48 -0700 (PDT)
User-agent: G2/1.0

Why are integers in Elisp restricted on some machines to 27 or 28 bits
of accuracy?  Wouldn't it be better if integers could be a full 32
bits in size, by borrowing from the following C++ code and translating
it to C and Elisp.

#include <iostream>
#define null (0)

template<class X>
class ptr
{
private:
   X* inner_ptr;

public:
   ptr()
   {
      inner_ptr = null;
   }

   ptr(const ptr& p)
   {
      assert(&p != null);
      inner_ptr = p.inner_ptr;
      if (inner_ptr != null)
      {
         inner_ptr->ref_count++;
      }
   }

   ptr& operator = (const ptr& p)
   {
      assert(this != null);
      assert(&p != null);
      //if (p.inner_ptr != null) // protect against s = s
      if (p != null) // protect against s = s
      {
         p.inner_ptr->ref_count++;
      }
      if (inner_ptr != null)
      {
         assert(inner_ptr->ref_count > 0); // protect against double
deletions
         inner_ptr->ref_count--;
         if (inner_ptr->ref_count == 0)
         {
            inner_ptr->ref_count = 1; // protect against internal
deletions
            delete inner_ptr;
         }
      }
      if (p == null)
      {
         inner_ptr = null;
      }
      else
      {
         inner_ptr = p.inner_ptr;
      }
      return *this;
   }

   ~ptr()
   {
      assert(this != null);
      if (inner_ptr != null)
      {
         assert(inner_ptr->ref_count > 0); // protect against double
deletions
         inner_ptr->ref_count--;
         if (inner_ptr->ref_count == 0)
         {
            inner_ptr->ref_count = 1; // protect against internal
deletions
            delete inner_ptr;
         }
         inner_ptr = null;
      }
   }

   ptr(X* x)
   {
      inner_ptr = x;
      if (inner_ptr != null)
      {
         inner_ptr->ref_count++;
      }
   }

   X* operator -> () const
   {
      assert(this      != null);
      assert(inner_ptr != null);
      return inner_ptr;
   }

   X& operator * () const
   {
      assert(this      != null);
      assert(inner_ptr != null);
      return *inner_ptr;
   }


   X* get_ptr() const
   {
      assert(this != null);
      return inner_ptr;
   }
   friend bool operator == (const ptr& p1, const ptr& p2)
   {
      if ((&p1 == null) && (&p2 == null))
      {
         return true;
      }
      else if ((&p1 == null) || (&p2 == null))
      {
         return false;
      }
      else
      {
         return (p1.inner_ptr == p2.inner_ptr);
      }
   }
   friend bool operator != (const ptr& p1, const ptr& p2)
   {
      return !(p1 == p2);
   }
};

class Big_Int
{
   int ref_count;
   template <class T> friend class ptr;

public:
   int v;
private:
   virtual ~Big_Int()
   {
   }

private:
   Big_Int(int v)
   {
      this->v = v;
      ref_count = 0;
   }

public:
   static ptr<Big_Int> ctor(int v)
   {
      return new Big_Int(v);
   }
};

int main()
{
   ptr<Big_Int> p = Big_Int::ctor(123);
   std::cout << "p=" << p->v << '\n';
}


reply via email to

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