Re: PRF & PLR flags max 32?

From: Henrik Stuart (hstuart@geocities.com)
Date: 01/25/02


Greetings,

> On Sun, 20 Jan 2002, Elie Rosenblum wrote:

> You can ignore std::vector<bool>.  It's ugly, stupid, and on the chopping
> block for C++0x.  A specialization of a container that is not, itself, a
> container is confusing and broken.  std::vector<bool> _looks_ like a
> container, but cannot be used like one.

  std::vector<bool> is not deprecated, nor is it on the way out, nor
  is it a container, std::vector is. std::vector is an implementation
  of a dynamically resizing array and as such using booleans as the
  type stored in the container would waste 7 bits since the smallest
  addressable pointer-unit is a byte (on some architectures even more).
  std::vector<bool> is a specialisation of a container to optimise the
  usage since a boolean really only requires one bit.
  Now, the benefit of std::vector<bool> over std::bitset<size> is that
  the vector is resizable during run-time.

  That means if you like some people have a dynamic system for classes
  and/or races where you can add/remove classes and/or races at
  run-time the std::vector<bool> makes a lot of sense to determine
  weather some pieces of equipment is usable by this class/race.

  std::vector<bool> can be used like any other template container with
  random access iterators, which merely stores booleans in an
  effective manner.

  For standard CircleMUD usage, however, std::vector<bool> warrants no
  attention, but it is, like the rest of the standard library, good to
  know if you are working with C++.

> std::bitset<N> merits a bit more attention (no pun intended).  It can be
> used as a drop-in replacement for bitvector_t if desired:
[snip]

  For any "normal" bitvector business where you know how many elements
  you need to control in your bitvector, std::bitset is by far
  preferable, and works rather well.

  The declaration of the elements should be something like:
  #define AFF_ELEM1  0
  #define AFF_ELEM2  1
  ...
  #define NUM_AFFECTS 37

  or the equivalent enum:
  enum Affects {
    AFF_ELEM1 = 0,
    AFF_ELEM2,
    ...

    NUM_AFFECTS // must always be last
  };

[snip]

>> Having looked at the code for the template, it's rather useful
>> generally but I would end up gutting it anyway just to get an
>> optimized version.

> To be honest, the standard STL implementation of std::bitset<N> is
> considerably better optimized than your bitvect class.

  Almost no matter what you do your STL container is better
  implemented than what you are doing (except if you choose a poorly
  written version of the template library, obviously). :o)

--
Yours truly,
  Henrik Stuart (http://www.unprompted.com/hstuart/)

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT