我有一些我想改进的代码。这是 2DBPP 变体之一的简单应用程序,您可以在 https://gist.github.com/892951 查看源代码。
这是我使用字符的概述(我想改用二进制值。)用“0”() 初始化一 block 内存:
...
char* bin;
bin = new (nothrow) char[area];
memset(bin, '\0', area);
有时我会检查特定的值:
if (!bin[j*height+k]) {...}
或 block :
if (memchr(bin+i*height+pos.y, '\1', pos.height)) {...}
或将值设置为“1”:
memset(bin+i*height+best.y,'\1',best.height);
我不知道有任何标准类型或方法可以处理二进制值。我如何使用位而不是字节?
有一个您可能感兴趣的相关问题 - C++ performance: checking a block of memory for having specific values in specific cells
谢谢!
编辑:还有一个更大的问题——它会是一种改进吗?我只关心时间。
最佳答案
初学者可以引用这篇文章: How do you set, clear, and toggle a single bit?
此外,请尝试查看 C++ 标准位集或位字段。
关于c++ - 如何在 C++ 程序中使用位值而不是字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5477867/