SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
ashkar
Topic Author
Posts: 274
Joined: October 17th, 2011, 9:25 am

Shared ptr

August 17th, 2015, 7:42 am

Hi guysI'm debugging some code that throws an access violation error that occurs at the end of the application when the call stack is unwound.Its a long code base so its difficult to explain the control flow here. I saw something odd in the assembly code. In the attached code I cant understand why the compiler is emitting this code to delete the shared ptr "std::tr1::shared_ptr<SynthForward>::~shared_ptr<SynthForward>" at various points at the end of these brackets. The synthetic forward shared ptrs are created a few function calls inside the call stack of this function so it shouldn't be deleted at this point. All optimisations have been turned off.There are other products being priced in this code along with synthetic forwards using the same architecture and they do not cause a problem. Cant figure out what is different about this particular class.Any ideas?Thanks
 
User avatar
ashkar
Topic Author
Posts: 274
Joined: October 17th, 2011, 9:25 am

Shared ptr

August 17th, 2015, 11:34 am

It seems that the assembler code in visual studio shows the wrong ownership type for shared_ptr i.e. the actual pointer being deleted is not QDSynthForward. I'll post back with more details if I find something interesting. Thx for the suggestion outrun.
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

Shared ptr

August 17th, 2015, 11:54 am

Hm, wondering, perhaps you can try comparing to another compiler on an otherwise unmodified platform -- is it reproducible?
 
User avatar
ashkar
Topic Author
Posts: 274
Joined: October 17th, 2011, 9:25 am

Shared ptr

August 18th, 2015, 10:35 am

I'm using VS2010, no threads. Debugging with tr1 shared_ptr is very misleading in VS. I had to dump out the assembler code to file which has the correct sharedptr types and then try best to match the buggy call stack in the debugger against the file output. I haven't been able to find the issue yet, its hidden somewhere deep in the code. Changing compiler is not an option but using boost shared_ptr shouldnt't be too much work. I'll try that when I get some time.
 
User avatar
Cuchulainn
Posts: 59944
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Shared ptr

August 18th, 2015, 12:41 pm

AFAIR tr1 (BTW kind of long in the tooth by now) and boost shared have the same interfaces. So, changing the namespace tr1 to boost is worth it although the issue may not disappear. Last time I used VS2010 (while ago) it supported C++11 smart pointers, but has less functionality than boost Thread. Are you only using tr1:shared_ptr? A random google gave this...It would seem that tr1 is a copy of boost in this context http://www.codesynthesis.com/~boris/blo ... r1-cxx-x0/ QuoteThere are other products being priced in this code along with synthetic forwards using the same architecture and they do not cause a problem.In that case, are there differences in how the two codes are written up? Can you modify the anomolous code to look like the correct code? Just an idea. Maybe a source code inspection will throw up something (no pun intended).
Last edited by Cuchulainn on August 17th, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59944
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Shared ptr

August 18th, 2015, 2:10 pm

QuoteOriginally posted by: outrunSounds like a horrible waste of time, difficult to fix because things are cryptic.Well, we just don't know if it is or not. OP has said nothing about this. It is called software maintenance and takes up a big chunk of software budgets.Maybe it's a show stopper.Wait on what OP has to say.
Last edited by Cuchulainn on August 17th, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59944
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Shared ptr

August 18th, 2015, 2:23 pm

Quoteabout the threads: ..so as a bonus for getting boost (I not sure if VS has native threads?) VS supports C++ Concurrency, so why would you want to know about Win32/MFC threads?
Last edited by Cuchulainn on August 17th, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 59944
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Shared ptr

August 18th, 2015, 3:11 pm

QuoteOriginally posted by: outrunWhen the debugger UI gives wrong information and you have to dump assembler to a file,... that's cryptic stuff and a waste of time.Ah, I see. Thanks.
Last edited by Cuchulainn on August 17th, 2015, 10:00 pm, edited 1 time in total.
 
User avatar
ashkar
Topic Author
Posts: 274
Joined: October 17th, 2011, 9:25 am

Shared ptr

August 19th, 2015, 5:11 pm

Finally hunted it down, some of the trade types were being cached by the framework thus returning same pointers. It wouldn't have been this difficult to track down if the debugger was more helpful. I'll try replacing with boost sharedptr and see if the debugger is any better. As Cuch says, since the interface is the same I might get away with find and replace. Although a painful experience, I feel bullet proof now !!!
 
User avatar
Cuchulainn
Posts: 59944
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Shared ptr

August 20th, 2015, 5:02 am

Plan B if boost does not solve it then std::shared_ptr<> works in VS2010.
 
User avatar
dd3
Posts: 246
Joined: June 8th, 2010, 9:02 am

Shared ptr

August 21st, 2015, 9:26 pm

Do you really need shared_ptr? I've rarely seen a case where it's justifiably used. Usually it's down to the programmer seeing it as a silver bullet and being unable to understand the lifetimes of objects is his own software.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On