-
March 29th, 2010, 05:32 PM
#16
Re: Force Assigning A Bool to a Single Bit
Originally Posted by Lindley
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.
-
March 29th, 2010, 05:56 PM
#17
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%.
Last edited by Lindley; March 29th, 2010 at 05:59 PM.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|