Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Linked List issue / debugging

I have been struggling with this problem for about 2 days now and I just cant figure out what the problem is.
I am making a linked list that points to a char array at different addresses.
So for the 8byte linked list, it points to an address every 8 bytes.
link lists 32bytes, 64bytes etc also follow the same pattern.
Here is the code that is giving me issues:
void CMemoryPoolManager::initializeLinkedList(char MM_pool[], int chunks, int chunkSize, int offset)
MemoryBlock current;
MemoryBlock *pCurrent = NULL;
pCurrent = &current;
for (int i=0; i < chunks; i++)
pCurrent = (MemoryBlock *)&MM_pool[sizeof(CMemoryPoolManager) +1 + (i * chunkSize) + offset];
pCurrent->pNext = NULL;
pCurrent->pPrevious = NULL;
pCurrent->bInUse = false;

switch (chunkSize)
case 8:
pCurrent->pNext = p8Byte;
if (p8Byte != NULL)
p8Byte->pPrevious = pCurrent;
p8Byte = pCurrent;
case 32:
pCurrent->siSize = 32;
pCurrent->pNext = p32Byte;
if (p32Byte != NULL)
p32Byte->pPrevious = pCurrent;
p32Byte = pCurrent;
case 64:
pCurrent->siSize = 64;
pCurrent->pNext = p64Byte;
if (p64Byte != NULL)
p64Byte->pPrevious = pCurrent;
p64Byte = pCurrent;

MemoryBlock is a struct in CMemoryPoolManager that holds the pointers next and previous
size is just for testing disregard that.
and the p##Byte are the linked lists inside CMemoryPoolManager
the line:
pCurrent = (MemoryBlock *)&MM_pool[sizeof(CMemoryPoolManager) +1 + (i * chunkSize) + offset];
gets the position of where to create the next "node".

Now on to the question / problem.
When creating the 8byte list,it doesnt link properly.
When it hits the "case 8:" line pCurrent->pNext changes by itself and subsequently changes the p8Byte links. So it never creates a proper list.
What really makes things weird is that the 32 and 64 byte lists are made correctly with no issues. Its the same code, it follows the same pattern, but the 8Byte list just doesnt work for whatever reason!
I have no clue as to why...ive tried a variety of things and nothing seems to help.
Can anyone suggest anything to try or see what the issue might be?
Any help at all would be GREATLY appreciated!!



  • AsmGuru62AsmGuru62 Posts: 6,519
    [color=Blue]Looking very closely you can see that 'case 8' is missing one line (compare it with other cases) - something about the size...[/color]
Sign In or Register to comment.