C++中具有共享对象验证的智能指针
Smart pointers in C++ with shared object-validation
我需要智能指针类或模板,它可以在"删除"发生后使其引用对象无效。关键是使指针在多线程应用程序的调试中可用。
这里有一个例子,只是伪代码:
void foo1(smart_ptr<myclass> ptr)
{
//some code
delete ptr;
//some other code
}
void foo2(smart_ptr<myclass> ptr)
{
//some code
function_wich_uses_ptr(ptr);
//some other code
}
int main()
{
myclass val = new myclass();
smart_ptr<myclass> ptr(&val);
//somehow make a copy of ptr
smart_ptr<myclass> ptr2(ptr);
//some code
thread_start(foo1, ptr);
thread_start(foo2, ptr2);
//
return 0;
}
所以,我需要foo2以某种方式跟踪foo1是否已经删除了引用到ptr的对象。一般来说,在指向单个obect的任何"活动"智能指针删除该对象后,指向同一对象的所有其他指针都应该以某种方式"感觉"到它,并将它自己的值设置为NULL。
UPD我的错误,例如不正确
您正在寻找一个没有所有权的智能指针。这正是boost::weak_ptr
所做的。
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 正在尝试了解输入验证循环
- 优先顺序:智能指针和类析构函数
- 如何在C++中检查2D数组中负值的输入验证
- 对于C++中使用智能指针的指针算术限制,有没有一种变通方法
- LibGit2 SSH身份验证失败
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- constexpr上下文中std::initializer_list的验证
- 智能指针作为无序映射键,并通过引用进行比较
- 智能指针概念所有权和寿命
- 正在验证c++中用户的整数输入
- 正在理解智能指针,但出现错误:未分配正在释放的指针
- 尝试使用智能指针时引发异常
- 加密++验证大文件签名
- C++卡验证问题
- 我可以制作指向智能指针的智能指针吗?
- 通过智能指针和转换对基本模板参数进行模板推导
- 验证指针链
- OpenCV 我应该使用智能指针来防止内存泄漏吗?
- C++中具有共享对象验证的智能指针