TR1共享阵列 [英] TR1 Shared Arrays
问题描述
我已经很难找到关于共享阵列TR1文档中引用。升压文档是相当清楚,还有就是C之间显著差异++新和新的[]前pressions。 shared_ptr的模板是为了指向正确把握动态分配使用的新反对建立。该shared_array模板是为了使用正确把握一个指向一个动态分配的数组新的[]。
I've had a hard time finding references in the TR1 documentation concerning shared arrays. The Boost documentation is fairly clear that there is a significant difference between the C++ "new" and "new[]" expressions. The shared_ptr template is meant to correctly hold a pointer to a dynamically allocated objected created using "new". The shared_array template is meant to correctly hold a pointer to a dynamically allocated array using "new[]".
我在更新一些code使用TR1的shared_ptr模板和相关功能的过程中,但我发现没有提到shared_array的。之间是否新和新的[],并正确地销毁这些指针TR1的shared_ptr实现差异化?至于我可以从看TR1规范来讲,它似乎没有。如果是这样的话,我应该还是使用升压shared_array模板新的[]类型的分配?
I'm in the process of updating some code to use the TR1 shared_ptr template and associated functions, but I've found no mention of shared_array. Does the TR1 shared_ptr implementation differentiate between "new" and "new[]", and destroy those pointers correctly? As far as I can tell from looking at the TR1 spec, it appears it does not. If this is the case, should I still be using the boost shared_array template for "new[]" style allocations?
推荐答案
这是正确的,没有在TR1没有shared_array。
That is correct, there is no shared_array in TR1.
您可以,但是,提供自己的删除对象执行删除[]如果你想使用此构造:
You can, however, provide your own deleter object to perform "delete []" if you wish using this constructor:
template<class Other, class D>
shared_ptr(Other* ptr, D dtor);
例如:
template<typename T>
struct my_array_deleter
{
void operator()(T* p)
{
delete [] p;
}
};
shared_ptr<int> sp(new int[100], my_array_deleter<int>());
这篇关于TR1共享阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!