Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stumped about this problem: Linked list, fixed size, data access

Status
Not open for further replies.

Weber1

Programmer
Sep 9, 2000
20
US
I have a class I am creating that is a template for a fixed-size linked list (basically an array of nodes with room for whatever kind of object is going in, a Next pointer, and an InUse flag.)
My problem is that when I try to "get" the data from a node, the system throws up an exception. Running the debugger, I can see that I have copied the object into the memory space and it is correct as far as I can tell. The "GetData" operation from the node should return a pointer to its object. (The object usually has a GetData function, as well, since the object is usually a class to hold the object that will fit the template to go into the list.)

The main program (fragment) with assembly code is here:
732: mytestclassOll->FindObject3(0)->GetData()->GetData();
00412A09 push 0
00412A0B mov ecx,dword ptr [ebp-3Ch]
00412A0E call @ILT+1380(C_ordered_linked_list_fixed_size<testclass>::FindObject3) (00401569)
00412A13 mov dword ptr [ebp-0DCh],eax
00412A19 mov edx,dword ptr [ebp-0DCh]
00412A1F mov eax,dword ptr [edx]
00412A21 mov esi,esp
00412A23 mov ecx,dword ptr [ebp-0DCh]
00412A29 call dword ptr [eax+4]

The last line is where the exception occurred (access violation). I do not know how to translate this assembly very well.

The code for GetData (of the node) looks like this:
template <class T>
T* C_ordered_linked_list_fixed_size_internal_node<T>::GetData()
{
return &myObject;
}

and the SetObject operation (where I copy the object into the node) looks like this:
template <class T>
C_ordered_linked_list_fixed_size_internal_node<T>::SetObject(T* theObject)
{
myObject = *theObject;
InUse = TRUE;
}

Sorry for writing a novel. Any insights are greatly appreciated!
 
Hmmm. Thanks for the advice, I may just do that. However, I have been hesitant to use STL classes because I cannot make them specifically like I want them; In this case, I don't really want a doubly-linked list because these nodes in the list are being used to manage memory (and I am already using enough extra memory to track my managed memory.) If I can't get this to work, I may just use the STL List or STL vector classes or something else that might work better.
 
Generated assembly code often isn't very efficient, but it's
secure. So the error lies within what you are doing in calling functions etc.
the error occurring in your program is like this:
register eax holds a value. this value is incremented by 4.
the new value serves as a pointer to an address and this address is the entrypoint of some function.
In your case this address is invalid.you should examine via assembly-debugging which values are created and how they are created.
but first you should look at your program-code.

sorry, can't help more

 
I am, unfortunately, more stumped than ever as to why this is not working since I have traced through with the debugger and it looks to me like it is working, except that for some reason the address of the head item is getting corrupted. The data of the first item in the list is being set appropriately (as far as I can tell) during Insert and the address of the head node item (0x007B1E30) is being passed out from the FindObject operation. However, I have my test driver set up to print out what the address is that it finds when it does the FindObject and it is NOT printing out the same address as what the debugger says is being passed out of the operation. IIRC, this problem happened to me before that the value being passed out was not the same at the level where it is being called (it says the address is 0x007B1E70). When I step through the debugger, it prints out the correct address, but when it still hangs when I do a GetData operation. But if I just run normally, it prints out the wrong address. Has anyone else had a similar problem with MS VC++?

Any help greatly appreciated!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top