shared-ptr

ntdll.dll [Frames below may be incorrect /missing, no symbols loaded for ntdll.dll]

感情迁移 提交于 2019-12-01 21:20:21
since a few weeks now I have run into this situation and it very upsetting, my program debugs very well, no errors, when I run the program it does the initial part of the job, after a few seconds It terminates to a 'break continue' option, and in the call stack when I have a look, it turns out that its an error from ntdll.dll and msvcr100d.dll it seems like a windows related SDK problem, it seems like a bad pointer too. I have somehow no control over this. I installed windows SDK to 7.0 but nothing seems to change, Using : Windows 7 64 bit, Boost 1.48, Visual studio compiler (full version),

Wrapping linked lists in iterators

谁说胖子不能爱 提交于 2019-12-01 20:59:37
问题 A set of APIs that I commonly use follow a linked-list pattern: struct SomeObject { const char* some_value; const char* some_other_value; SomeObject* next; } LONG GetObjectList( SomeObject** list ); void FreeObjectList( SomeObject* list ); This API is not mine and I cannot change it. So, I'd like to encapsulate their construction/destruction, access, and add iterator support. My plan is to do something like this: /// encapsulate access to the SomeObject* type class MyObject { public: MyObject

Is there a way to increase the efficiency of shared_ptr by storing the reference count inside the controlled object?

谁说胖子不能爱 提交于 2019-12-01 20:39:28
This is becoming a common pattern in my code, for when I need to manage an object that needs to be noncopyable because either A. it is "heavy" or B. it is an operating system resource, such as a critical section: class Resource; class Implementation : public boost::noncopyable { friend class Resource; HANDLE someData; Implementation(HANDLE input) : someData(input) {}; void SomeMethodThatActsOnHandle() { //Do stuff }; public: ~Implementation() { FreeHandle(someData) }; }; class Resource { boost::shared_ptr<Implementation> impl; public: Resource(int argA) explicit { HANDLE handle =

Wrapping linked lists in iterators

好久不见. 提交于 2019-12-01 19:43:21
A set of APIs that I commonly use follow a linked-list pattern: struct SomeObject { const char* some_value; const char* some_other_value; SomeObject* next; } LONG GetObjectList( SomeObject** list ); void FreeObjectList( SomeObject* list ); This API is not mine and I cannot change it. So, I'd like to encapsulate their construction/destruction, access, and add iterator support. My plan is to do something like this: /// encapsulate access to the SomeObject* type class MyObject { public: MyObject() : object_( NULL ) { }; MyObject( const SomeObject* object ) : object_( object ) { }; const char*

C++: Creating a shared object rather than a shared pointer to an object

我与影子孤独终老i 提交于 2019-12-01 19:30:00
boost::shared_ptr really bothers me. Certainly, I understand the utility of such a thing, but I wish that I could use the shared_ptr<A> as an A* . Consider the following code class A { public: A() {} A(int x) {mX = x;} virtual void setX(int x) {mX = x;} virtual int getX() const {return mX;} private: int mX; }; class HelpfulContainer { public: //Don't worry, I'll manager the memory from here. void eventHorizon(A*& a) { cout << "It's too late to save it now!" << endl; delete a; a = NULL; } }; int main() { HelpfulContainer helpfulContainer; A* a1 = new A(1); A* a2 = new A(*a1); cout << "*a1 = " <

Why doesn't shared_ptr permit direct assignment

若如初见. 提交于 2019-12-01 15:04:59
So when using shared_ptr<Type> you can write: shared_ptr<Type> var(new Type()); I wonder why they didn't allow a much simpler and better (imo): shared_ptr<Type> var = new Type(); Instead to achieve such functionality you need to use .reset() : shared_ptr<Type> var; var.reset(new Type()); I am used to OpenCV Ptr class that is a smart pointer that allows direct assignment and everything works fine The issue with allowing a raw pointer to be implicitly converted into a std::shared_ptr can be demonstrated with void foo(std::shared_ptr<int> bar) { /*do something, doesn't matter what*/ } int main()

Set shared_ptr with new_pointer that is old_pointer + offset

天大地大妈咪最大 提交于 2019-12-01 14:55:48
Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I can parse it, and during this I retrieve some header information (a few first dwords). Then actual data follows. Without giving much more context, it's handy for me to to set mentioned shared pointer to new address that is beginning of actual data . This address is still in alocated memory. But how to set without losing it? A question is (yes/no): Is it possible to set p to offset of prevous pointer,

Why doesn't shared_ptr permit direct assignment

懵懂的女人 提交于 2019-12-01 13:55:35
问题 So when using shared_ptr<Type> you can write: shared_ptr<Type> var(new Type()); I wonder why they didn't allow a much simpler and better (imo): shared_ptr<Type> var = new Type(); Instead to achieve such functionality you need to use .reset() : shared_ptr<Type> var; var.reset(new Type()); I am used to OpenCV Ptr class that is a smart pointer that allows direct assignment and everything works fine 回答1: The issue with allowing a raw pointer to be implicitly converted into a std::shared_ptr can

shared_ptr with vector

扶醉桌前 提交于 2019-12-01 13:45:44
I currently have vectors such as: vector<MyClass*> MyVector; and I access using MyVector[i]->MyClass_Function(); I would like to make use of shared_ptr . Does this mean all I have to do is change my vector to: typedef shared_ptr<MyClass*> safe_myclass vector<safe_myclass> and I can continue using the rest of my code as it was before? vector<shared_ptr<MyClass>> MyVector; should be OK. But if the instances of MyClass are not shared outside the vector, and you use a modern C++11 compiler, vector<unique_ptr<MyClass>> is more efficient than shared_ptr (because unique_ptr doesn't have the ref count

Set shared_ptr with new_pointer that is old_pointer + offset

南楼画角 提交于 2019-12-01 13:41:26
问题 Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I can parse it, and during this I retrieve some header information (a few first dwords). Then actual data follows. Without giving much more context, it's handy for me to to set mentioned shared pointer to new address that is beginning of actual data . This address is still in alocated memory. But how to