Computer Chess Club Archives


Search

Terms

Messages

Subject: size of C++ class question...

Author: James Long

Date: 22:53:23 02/13/99



The use the following class in one of my programs.
I'm trying to find ways to trim it down to four
bytes, so that I can do a UNION with an int for
quick comparisons.

A quick summation of the size of the private
variables comes up to 9 bytes. However, the actual
size of this class is 12 bytes.

Could somebody explain where the extra 3 bytes
comes from? (Is it the enumeration, or the constructor?
Do the functions add to the size??)

Even if I removed the score field and used the high
order bits of the source, dest, captured, and mover
fields to represent special moves, I would still be a 7
or so bytes.

Suggestions on reducing the size of this thing
would be greatly appreciated.  As you can see, the
overloaded operators '==' and '!=' are very
inefficient.

--
James



class Move
{
public:
   enum SpecialType { None,EpCapture,
      Queen_Promotion,Rook_Promotion,
      Bishop_Promotion,Knight_Promotion };
   Move()
   {
      Reset();
   }
   Move (const Move &m);
   Move (const Square::LocationType s,
      const Square::LocationType d,
      const Piece::NameType m,
      const Piece::NameType c);
   Move (const Square::LocationType s,
      const Square::LocationType d,
      const Piece::NameType m,
      const Piece::NameType c,
      const SpecialType sp);
   void Set(const Move &m);
   int8 Source() const
   { return m_source; }
   int8 Dest() const
   { return m_dest; }
   int8 Mover() const
   { return m_mover; }
   int8 Captured() const
   { return m_captured; }
   int8 Special() const
   { return m_special; }
   int32 Score() const
   { return m_score; }
   void Reset(void)
   {
      m_source = Square::Invalid;
      m_dest = Square::Invalid;
      m_mover = Piece::Empty;
      m_captured = Piece::Empty;
      m_special = None;
   }
   void setSource(const Square::LocationType s)
   {
      m_source = s;
   }
   void setDest(const Square::LocationType s)
   {
      m_dest = s;
   }
   void setMover(const Piece::NameType p)
   {
      m_mover = p;
   }
   void setCaptured(const Piece::NameType p)
   {
      m_captured = p;
   }
   void setSpecial(const SpecialType s)
   {
      m_special = s;
   }
   void setScore(const int32 s)
   {
      m_score = s;
   }
   int operator != (const Move &m)
   {
      return ((m.Source() != m_source) ||
         (m.Dest() != m_dest) ||
         (m.Mover() != m_mover) ||
         (m.Captured() != m_captured) ||
         (m.Special() != m_special));
   }
   int operator == (const Move &m)
   {
      return ((m.Source() == m_source) &&
         (m.Dest() == m_dest) &&
         (m.Mover() == m_mover) &&
         (m.Captured() == m_captured) &&
         (m.Special() == m_special));
   }
private:
   int8 m_source;
   int8 m_dest;
   int8 m_mover;
   int8 m_captured;
   int8 m_special;
   int32 m_score;
};




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.