Hi!
In the following method:
Display All
Is it better to change this part of code :
to this :
I don't know the reason of casting PCurr to Char** and using array index to assign. Is there any reason to do that?
Thank you!
In the following method:
Source Code
- unsigned char* MemoryPool::AllocateNewMemoryBlock(void)
- {
- // calculate the size of each block and the size of the actual memory allocation
- size_t blockSize = m_chunkSize + CHUNK_HEADER_SIZE; // chunk + linked list overhead
- size_t trueSize = blockSize * m_numChunks;
- // allocate the memory
- unsigned char* pNewMem = (unsigned char*)malloc(trueSize);
- if (!pNewMem)
- return NULL;
- // turn the memory into a linked list of chunks
- unsigned char* pEnd = pNewMem + trueSize;
- unsigned char* pCurr = pNewMem;
- while (pCurr < pEnd)
- {
- // calculate the next pointer position
- unsigned char* pNext = pCurr + blockSize;
- // set the next & prev pointers
- unsigned char** ppChunkHeader = (unsigned char**)pCurr;
- ppChunkHeader[0] = (pNext < pEnd ? pNext : NULL);
- // move to the next block
- pCurr += blockSize;
- }
- return pNewMem;
- }
Is it better to change this part of code :
to this :
I don't know the reason of casting PCurr to Char** and using array index to assign. Is there any reason to do that?
Thank you!