CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Mar 2010
    Posts
    14

    Re: Force Assigning A Bool to a Single Bit

    Quote Originally Posted by Lindley View Post
    Might want to re-check your math. While I'm not sure what you mean by "resolution of 200", 512x512 bools of 4 bytes each will only take up 1 megabyte.
    A 512 x 512 map with each unit being divided into about 4 squares.

    So 512 X 512 x 200 X 4 = 209715200 bytes.

  2. #17
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Force Assigning A Bool to a Single Bit

    Ah. Well, for a space that large, another consideration is how many of those bytes you typically expect to be set. If the percentage is high, then one of the aforementioned approaches will work. But if you are only expecting to actually set a relatively small number of those bits, then you should consider a sparse representation. Something like this:

    Code:
    struct Coordinate
    {
        short x, y, r, s;//x,y is [0,511], r is [0,199], s is [0,3].
        bool operator<(const Coordinate &rhs) const
        {
            if (x < rhs.x)
                 return true;
            if (x == rhs.x && y < rhs.y)
                 return true;
            if (x == rhs.x && r == rhs.y && r < rhs.r)
                 return true;
            if (x == rhs.x && r == rhs.y && r == rhs.r && s < rhs.s)
                 return true;
            return false;
        }
    };
    
    std::map<Coordinate,bool> active;
    Since each entry will require at least 12 bytes (probably more like 20 after map overhead), this would only represent an improvement over a dynamic_bitset if the percentage of active bits is expected to be is < 1&#37;.
    Last edited by Lindley; March 29th, 2010 at 05:59 PM.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured