Linked List issue / debugging - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Linked List issue / debugging

ghostfacelzghostfacelz Posts: 37Member
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:
[code]
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;
break;
case 32:
pCurrent->siSize = 32;
pCurrent->pNext = p32Byte;
if (p32Byte != NULL)
p32Byte->pPrevious = pCurrent;
p32Byte = pCurrent;
break;
case 64:
pCurrent->siSize = 64;
pCurrent->pNext = p64Byte;
if (p64Byte != NULL)
p64Byte->pPrevious = pCurrent;
p64Byte = pCurrent;
break;

}
}
}
[/code]
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:
[code]
pCurrent = (MemoryBlock *)&MM_pool[sizeof(CMemoryPoolManager) +1 + (i * chunkSize) + offset];
[/code]
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!!
Thanks!

=Ghost=>

Comments

Sign In or Register to comment.