我有这段代码
unsigned char* MemoryPool::GetNext(unsigned char* pBlock)
{
unsigned char** ppChunkHeader = (unsigned char**)pBlock;
return ppChunkHeader[0];
}
取自这里http://gamecode4.googlecode.com/svn/trunk/Source/GCC4/Memory/MemoryPool.cpp
我不知道从 unsigned char* 转换为 unsigned char** 的作用。如果我添加这些代码行:
unsigned char* MemoryPool::GetNext(unsigned char* pBlock)
{
unsigned char **ppChunkHeader = (unsigned char**)pBlock;
printf("ppChunkHeader %p\n", ppChunkHeader);
printf("pBlock %p\n", pBlock);
printf("sizeof(unsigned char*) = %i\n", sizeof(unsigned char*));
printf("ppChunkHeader[0] %p\n", ppChunkHeader[0]);
printf("&pBlock[0] %p\n", &pBlock[0]);
printf("ppChunkHeader[0] - &pBlock[0] = %p\n", (ppChunkHeader[0] - &pBlock[0]));
return ppChunkHeader[0];
}
输出是
ppChunkHeader 00DCB498
pBlock 00DCB498
sizeof(unsigned char*) = 4
ppChunkHeader[0] 00DCB4A1
&pBlock[0] 00DCB4A1
ppChunkHeader[0] - &pBlock[0] = 00000009
我认为值得一提的是,在我的代码中,pBlock 指向一个由 9 个元素组成的数组。
谢谢你。