1
鑑於我分配內存是這樣的:在平坦的位域實現中獲取所需位的字節地址?
Create(int width, int height, int depth)
{
size_t numBits = width * height * depth;
size_t numBytes = numBits/8 + numBits % 8 != 0 ? 1 : 0;
bytes = malloc(numBytes);
...
現在我想要得到的字節對於一個給定的x,y偏移,B:
DoSomething(int x, int y, int bit)
{
Byte* byte = bytes + ... some offset ...
例如,如果我說Create(3, 3, 3)
然後DoSomething(0, 1, 1)
我會計算字節偏移量爲0.如果我說DoSomething(0, 2, 2)
這將是第九位,所以我會計算偏移量爲1.
一旦我有字節我可以執行操作 我需要。