[英]boost::make_shared and C++Builder VCL objects
I've tried switching some C++Builder 2010 code using new
to use boost::make_shared<>
, as below. 我尝试使用
new
切换一些C ++ Builder 2010代码以使用boost::make_shared<>
,如下所示。
Old: 旧:
boost::shared_ptr<TStringList> l(new TStringList());
New: 新:
boost::shared_ptr<TStringList> l(boost::make_shared<TStringList>());
l->Add("foo"); //dies here
The old code works, but the new code dies when I try and use the pointer (AV, or just hangs). 旧代码有效,但是当我尝试使用指针(AV或只是挂起)时,新代码就会消失。 I've used
make_shared
and shared_ptr
successfully before, but never with TObject
descendants. 我以前曾经成功使用过
make_shared
和shared_ptr
,但从未与TObject
后代一起使用过。 Is this a known problem - perhaps something to do withe the way make_shared
uses placement new()
?? 这是一个已知问题吗?也许与
make_shared
使用new()
放置方式有关?
我认为placement new
的placement new
确实存在问题,因为TObject
对new
内存分配感到满意(因为C ++ Builder的RTL在内部将C / C ++的内存例程路由到VCL项目中的Delphi RTL例程),而placement new
则没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.