C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Linked List issue / debugging Posted by ghostfacelz on 14 May 2011 at 10:49 AM
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;
			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;

		}
	}
}

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!!
Thanks!

=Ghost=>
Thread Tree
ghostfacelz Linked List issue / debugging on 14 May 2011 at 10:49 AM
AsmGuru62 Re: Linked List issue / debugging on 15 May 2011 at 4:33 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.