12 Replies - 2436 Views - Last Post: 09 June 2008 - 03:12 PM Rate Topic: -----

#1 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

transferring data from one deque to another, deep copy

Posted 05 June 2008 - 11:06 AM

if ( numEntries > 0 ) //equals one in this case, so *itsPreDataFaultListPtr has one element
      	{
		Sequence<M *> * seqPtr = new CSequence<M *>(numEntries);
  		FaultInfo * faultPtr = NULL;
		for (LongNatural i=0; i < numEntries; i++)
		{
                   LongNatural myVarDataCount = 1;
		   //LongNatural myVarDataCount = (*itsPreDataFaultListPtr)[i]->varData.size(); //used to crash here so tried hard-coding it and see what happened.  Same problem with varData accessing deadDead.
		   Sequence<FaultEventInfo::ExceptionVariableData > * varDataTypeListPtr=NULL;
                   Sequence<Value *> * varDataListPtr=NULL;
                   varDataTypeListPtr = new CSequence<FaultEventInfo::ExceptionVariableData >(myVarDataCount);
		   varDataListPtr = new CSequence<Value *>(myVarDataCount);
                   for(LongNatural j= 0; j < myVarDataCount; j++)
		   {
                        Sequence<Value *> * varDataListPtr=NULL;
                        if (theFaultEntries[i].varData[j]->GetVarDataType() != FaultEventInfo::none) //it crashes here when it tries to access varData
 in .h file:
struct FaultNode {
       TimeA  time;
       Id faultID;
       LongNatural primaryCounterValue;
       deque<FaultNodeDatas*> varData;
};



//The crash seems to move with varData. It is trying to access memory that is outside of the acceptable range (deadDead). I'm not sure if the problem is that I'm indexing into the varData deque. I do that in methods above also. I added the deque to the FaultNode struct. VarData used to be a single value and now needs to be multiple values. The original code had a lot of deep copies, so I'm still doing that. I was having trouble using iterators and still get it to compile. If the problem is the way I iterate through the deque or that I am indexing into the deque, how else would I do that and keep the deep copy?[/size]


Mod Edit: Code tags added => :code:

Is This A Good Question/Topic? 0
  • +

Replies To: transferring data from one deque to another, deep copy

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 11:15 AM

Please put your code in the tags properly :code: and use a decent size, I can't read that properly.
Was This Post Helpful? 0
  • +
  • -

#3 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 11:36 AM

[code]if ( numEntries > 0 ) //equals one in this case, so *itsPreDataFaultListPtr has one element[\code]
[code]{[\code]
[code]Sequence<M *> * seqPtr = new CSequence<M *>(numEntries);[\code]
[code]FaultInfo * faultPtr = NULL;[\code]
[code]for (LongNatural i=0; i < numEntries; i++)[\code]
[code]{[\code]
[code]LongNatural myVarDataCount = 1;[\code]
[code]//LongNatural myVarDataCount = (*itsPreDataFaultListPtr)[i]->varData.size[code](); //used to crash here so tried hard-coding it and see what happened. Same [code]problem with varData accessing deadDead.[\code]
[code]Sequence<FaultEventInfo::ExceptionVariableData > * varDataTypeListPtr=NULL;[\code]
[code]Sequence<Value *> * varDataListPtr=NULL;[\code]
[code]varDataTypeListPtr = new CSequence<FaultEventInfo::ExceptionVariableData >(myVarDataCount);[\code]
[code]varDataListPtr = new CSequence<Value *>(myVarDataCount);[\code]
[code]for(LongNatural j= 0; j < myVarDataCount; j++)[\code]
[code]{[\code]
[code]Sequence<Value *> * varDataListPtr=NULL;[\code]
[code]if (theFaultEntries[i].varData[j]->GetVarDataType() != FaultEventInfo::none) //it crashes here when it tries to access varData[\code]
[code]in .h file:[\code]
[code]struct FaultNode {[\code]
[code]TimeA time;[\code]
[code]Id faultID;[\code]
[code]LongNatural primaryCounterValue;[\code]
[code]deque<FaultNodeDatas*> varData;[\code]
};[\code]
[code]//The crash seems to move with varData. It is trying to access memory that is outside of the acceptable range (deadDead). I'm not sure if the problem is that I'm indexing into the varData deque. I do that in methods above also. I added the deque to the FaultNode struct. VarData used to be a single value and now needs to be multiple values. The original code had a lot of deep copies, so I'm still doing that. I was having trouble using iterators and still get it to compile. If the problem is the way I iterate through the deque or that I am indexing into the deque, how else would I do that and keep the deep copy?
[\code]
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 11:43 AM

It only needs to go between the code tags once~
[*code=cpp]paste
your
code
here[*/code]


Just don't use the *s - take those out :)

This post has been edited by gabehabe: 05 June 2008 - 11:45 AM

Was This Post Helpful? 0
  • +
  • -

#5 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 11:54 AM

View Postgabehabe, on 5 Jun, 2008 - 11:43 AM, said:

It only needs to go between the code tags once~
[*code=cpp]paste
your
code
here[*/code]


Just don't use the *s - take those out :)



How do I post with out the *'s and still show that in the code the way it's supposed to be? My original post had the
[code] stuff
stuff [\code] format and it looked awful.
Was This Post Helpful? 0
  • +
  • -

#6 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 11:59 AM

I don't know why I didn't think of this before.
if ( numEntries > 0 ) //equals one in this case, so *itsPreDataFaultListPtr has one element
{
Sequence<M *> * seqPtr = new CSequence<M *>(numEntries);
FaultInfo * faultPtr = NULL;
for (LongNatural i=0; i < numEntries; i++)
{
LongNatural myVarDataCount = 1;
//LongNatural myVarDataCount = (*itsPreDataFaultListPtr)[i]->varData.size(); //used to crash here so tried hard-coding it and see what happened. Same problem with varData accessing deadDead.
Sequence<FaultEventInfo::ExceptionVariableData > * varDataTypeListPtr=NULL;
Sequence<Value *> * varDataListPtr=NULL;
varDataTypeListPtr = new CSequence<FaultEventInfo::ExceptionVariableData >(myVarDataCount);
varDataListPtr = new CSequence<Value *>(myVarDataCount);
for(LongNatural j= 0; j < myVarDataCount; j++)
{
Sequence<Value *> * varDataListPtr=NULL;
if (theFaultEntries[i].varData[j]->GetVarDataType() != FaultEventInfo::none) //it crashes here when it tries to access varData
in .h file:
struct FaultNode {
TimeA time;
Id faultID;
LongNatural primaryCounterValue;
deque<FaultNodeDatas*> varData;
};


EDIT: Could I see your whole code? I might be able to make better sense of it from that.

The problem was that in your first post, you used \ instead of / it's a common mistake. :)

This post has been edited by gabehabe: 05 June 2008 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#7 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 12:23 PM

Sorry about that! I emailed the code to you. I didn't want to post the entire thing here.
Was This Post Helpful? 0
  • +
  • -

#8 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: transferring data from one deque to another, deep copy

Posted 05 June 2008 - 05:37 PM

It's difficult to determine the issue with the amount of code given.

I'd assume that each FaultNode is being allocated with the new operator just like everything here in the code posted?

If calling the size method crashes, I'm sure iterating through the deque isn't going to be any better.

It's sometimes useful when debugging pointer problems to write pointer values to some sort of debug output. Contrary to popular belief, it can be helpful at times. Other than the obvious dereference of a null pointer, on Windows x86 32-bit, if the pointer is pointing to the stack, it will likely be in the form 0x2xxxxx, or if it's on the heap, it will likely be 0x3xxxxx. If it's anything else, it's either garbage, or it's to some global variable. I'm not sure about Linux, but it's quite easy to test.
Was This Post Helpful? 0
  • +
  • -

#9 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

Re: transferring data from one deque to another, deep copy

Posted 06 June 2008 - 08:19 AM

FaultNodes aren't being newed up because they are not pointers.

We know when it crashes that it is looking at memory outside of the usable area. I'm not sure why. Thanks for the help!
Was This Post Helpful? 0
  • +
  • -

#10 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: transferring data from one deque to another, deep copy

Posted 06 June 2008 - 03:12 PM

So, this means that operator-> has been overloaded for the following:

Michele said:

//LongNatural myVarDataCount = (*itsPreDataFaultListPtr)[i]->varData.size();


It's using pointer syntax (->, and even *), so that's why I brought up pointers. This is a smart pointer of some sort, or an internal reference to something else?
Was This Post Helpful? 0
  • +
  • -

#11 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

Re: transferring data from one deque to another, deep copy

Posted 09 June 2008 - 12:45 PM

itsPreDataFaultListPtr is defined in the .h file as

Sequence<FaultNode *> * itsPreDataFaultListPtr;

where a Sequence is a container, the <> is a template where T is a FaultNode pointer (struct in .h file), and itsPreDataFaultListPtr is a pointer.

I thought you were referring to something else. Sorry! In my DeclareFault method, my FaultNode is not a pointer. I populate the varData deque by adding the info to the pointer to FaultNodeDatas and pushing it onto the varData deque.

This post has been edited by Michele: 09 June 2008 - 12:49 PM

Was This Post Helpful? 0
  • +
  • -

#12 Michele  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-June 08

Re: transferring data from one deque to another, deep copy

Posted 09 June 2008 - 01:19 PM

P.S. The last discussion got me looking closer at my InternalDeclareFault method, and I was not: newing up a FaultNodeDatas and populating it, then pushing it onto the deque. I was accessing the ith node of the deque and setting the "FaultNodeDatas" that probably wasn't considered to be there because I hadn't pushed it on yet. I had crashes previously in DeclareFault when I did this. I wonder why it didn't crash in InternalDeclareFault. I wonder if this is why it was crashing when I tried to get the size in my Body method that I posted above. We'll see tomorrow when I try and test it again.
Was This Post Helpful? 0
  • +
  • -

#13 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: transferring data from one deque to another, deep copy

Posted 09 June 2008 - 03:12 PM

One thing to consider is that pointers to deque elements are not necessarily valid after making modifications to the deque (using insert(), push_front(), pop_front(), etc.). A deque is not a linked list, but is more like a vector internally. Items are shuffled around in an array that is variably sized. The exact details are likely to be implementation specific.. So taking the address of a deque element is usually not a good thing unless one decides not to edit the deque after storing a pointer to an element.

Of course, some deque implementations don't do much bounds checking, so if one exceeds the bounds, one is likely to receive garbage, which that garbage ends up being a pointer that is dereferenced. So your explanation could very well be the culprit.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1