views:

379

answers:

5

I cannot get std::tr1::shared_ptr for my WinMobile project since the STL for WinCE is maintained by a different team at Microsoft :( aarrgh...

Anyone worked with another thread-safe, reference counting smart pointers? I'm actually using yasper which seems to be good.

Thank you very much.

+3  A: 

Boost Smart Pointers. In particular boost::shared_ptr. I am pretty sure they are supported for your platform. This is where tr1::shared_ptr came from.

grepsedawk
A: 

yasper::ptr seems to be similar to Boost Smart Pointers, altough shared_ptr of course has more features.

In the scarce yasper::ptr documentation an example of pointer assignment appears:

 //preferred  
ptr<SomeClass> p1(new SomeClass);

 //less safe  
ptr<SomeClass> p2 = new SomeClass;

Why the second from would be 'less safe'?

Hernán
it's less safe because that is an implicit conversion from a raw pointer to ptr<> template. consider void function(ptr<foo> f) { } foo * p = new foo; function(p); p->bar = 10; // oops
Johannes Schaub - litb
Thank you very much for your response. That means p->bar may be invalid since p address was released by the smart pointer at function scope termination?
Hernán
+2  A: 

Have you looked at STLPort or the Dinkum TR1 library? Both have a much more complete port for CE.

ctacke
A: 

Yes I'm thinking into using shared_ptr, but Visual C++ 2008 does not have it under std::tr1 for WinCE builds, so may be I look those alternatives, thank you. I'm happy with yasper::ptr but I doubt it's thread safe.

Hernán
+4  A: 

I'd also recommend boost::shared_ptr. You can do what I did for a library, and use a #define to switch between std::tr1::shared_ptr and boost::shared_ptr, depending on the capabilities of the compiler. That way your code doesn't need to be modified [much] if/when the CE team add tr1 support. Just my 2c.

Nick