It's common to declared contained objects as a pointers to that class, while "forward declarating" them in header file. This in order to reduce physical dependencies in code.
For example
class B; // forward declaration
class A {
private:
B* pB;
};
Would it be good idea to declare such a member as shared_ptr, instead of ...
How do shared pointers know how many pointers point to that object? (shared_ptr, in this case)
...
I'm very interested in the user-space RCU (read-copy-update), and trying to simulate one via tr1::shared_ptr, here is the code, while I'm really a newbie in concurrent programming, would some experts help me to review?
The basic idea is, reader calls get_reading_copy() to gain the pointer of current protected data (let's say it's gener...
Following the advice of this page, I'm trying to get shared_ptr to call IUnknown::Release() instead of delete:
IDirectDrawSurface* dds;
... //Allocate dds
return shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(&IUnknown::Release));
error C2784: 'std::const_mem_fun1_ref_t<_Result,_Ty,_Arg> std::mem_fun_ref(Result (_thiscall _Ty::* )...
Hi,
I'm trying to use smart pointers such as auto_ptr, shared_ptr. However, I don't know how to use it in this situation.
CvMemStorage *storage = cvCreateMemStorage();
... use the pointer ...
cvReleaseMemStorage(&storage);
I'm not sure, but I think that the storage variable is just a malloc'ed memory, not a C++ class object. Is there...
Is it possible to get a raw pointer from boost::weak_ptr? Boost's shared_ptr has get() method and "->" operator. Is there some rationale behind weak_ptr not having the same functionality?
...
Silly question, but say you have class Foo:
class Foo
{
public:
typedef boost::shared_ptr<Foo> RcPtr;
void non_const_method() {}
void const_method() const {}
};
Having a const Foo::RcPtr doesn't prevent non-const methods from being invoked on the class, the following will compile:
#include <boost/shared_ptr.hpp>
int mai...
Since boost::shared_ptr could be called very frequently and simply returns a pointer, isn't the -> operator a good candidate for being inlined?
T * operator-> () const // never throws
{
BOOST_ASSERT(px != 0);
return px;
}
Would a good compiler automatically inline this anyway?
Should I lose any sleep over this? :-)
...
I want objects managed by a shared_ptr to be allocated from a pool, say Boost's Pool interface, how can this be achieved?
...
I am so frustrated right now after several hours trying to find where shared_ptr is located. None of the examples I see show complete code to include the headers for shared_ptr (and working). Simply stating std, tr1 and <memory> is not helping at all! I have downloaded boosts and all but still it doesn't show up! Can someone help me by ...
My application problem is the following -
I have a large structure foo. Because these are large and for memory management reasons, we do not wish to delete them when processing on the data is complete.
We are storing them in std::vector<boost::shared_ptr<foo>>.
My question is related to knowing when all processing is complete. Fir...
Hello!
I can't understand why does the following code produce memory leaks (I am using boost::shared_ptr with static class instance). Could someone help me?
#include <crtdbg.h>
#include <boost/shared_ptr.hpp>
using boost::shared_ptr;
#define _CRTDBG_MAP_ALLOC
#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
static struct myclass {
...
I've got a class that has a tr1::shared_ptr as a member, like so:
class Foo
{
std::tr1::shared_ptr<TCODBsp> bsp;
void Bar();
}
In member function Bar, I try to assign it like this:
bsp = newTCODBsp(x,y,w,h);
g++ then gives me this error
no match for ‘operator=’ in ‘((yarl::mapGen::MapGenerator*)this)->yarl::mapGen::MapGene...
Hello!
I recently started investigating Qt for myself and have the following question:
Suppose I have some QTreeWidget* widget. At some moment I want to add some items to it and this is done via the following call:
QList<QTreeWidgetItem*> items;
// Prepare the items
QTreeWidgetItem* item1 = new QTreeWidgetItem(...);
QTreeWidgetItem* ...
I want to cast the const-ness out of a boost::shared_ptr, but I boost::const_pointer_cast is not the answer. boost::const_pointer_cast wants a const boost::shared_ptr, not a boost::shared_ptr. Let's forego the obligitory 'you shouldn't be doing that'. I know... but I need to do it... so what's the best/easiest way to do it?
For clari...
Profiling some code that heavily uses shared_ptrs, I discovered that reset() was surprisingly expensive.
For example:
struct Test {
int i;
Test() {
this->i = 0;
}
Test(int i) {
this->i = i;
}
} ;
...
auto t = make_shared<Test>(1);
...
t.reset(somePointerToATestObject);
Tracing the reset() in th...
I have an object which has both a copy constructor and assignment operator defined. It is enclosed inside a shared pointer.
I want to make another shared pointer that contains a copy of the original shared pointer (i.e. new shared pointer to a new memory location, which however, has the same data as the original object).
Thanks for an...
I've just started working on a new codebase where each class contains a shared_ptr typedef (similar to this) like:
typedef boost::shared_ptr<MyClass> Ptr;
Is the only purpose to save typing boost::shared_ptr?
If that is the case, is the only reason not to do
#define Ptr boost::shared_ptr
in one common header the general problem...
hello, I have this snippet of the code:
void addLineRelative(LineNumber number, LineNumber relativeNumber) {
list<shared_ptr<Line> >::iterator i;
findLine(i, number);
if(i == listOfLines.end()){
throw "LineDoesNotExist";
}
line 15 if(dynamic_cast<shared_ptr<FamilyLine>...
I'm creating a wrapper for a HANDLE that does not work with DuplicateHandle, so instead I am trying to wrap the handle in a shared_ptr.
Imagine the following code:
class CWrapper
{
public:
CWrapper() :
m_pHandle(new HANDLE, &CWrapper::Close)
{
//code to open handle
}
private:
void Close()
{
...