向量的自定义分配器示例代码 [英] Custom allocator sample code for vector
问题描述
我正在寻找std :: vector的任何自定义分配器示例代码。
谢谢。
-
Alex Vinokur
http://mathforum.org/ library / view / 10978.html
http://sourceforge.net / users / alexvn
I am looking for any custom allocator sample code for std::vector.
Thanks.
--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
推荐答案
" Alex Vinokur" <人**** @ big-foot.com>在消息中写道
news:2n *********** @ uni-berlin.de ...
"Alex Vinokur" <al****@big-foot.com> wrote in message
news:2n***********@uni-berlin.de...
我正在寻找任何自定义分配器示例代码为std :: vector。
I am looking for any custom allocator sample code for std::vector.
http://www.josuttis.com/libbook/memo...lloc1.cpp.html
Sharad Kala <无****************** @ yahoo.com>在消息新闻中写道:2n *********** @ uni-berlin.de ...
"Sharad Kala" <no******************@yahoo.com> wrote in message news:2n***********@uni-berlin.de...
Alex Vinokur <人**** @ big-foot.com>在消息中写道
新闻:2n *********** @ uni-berlin.de ...
"Alex Vinokur" <al****@big-foot.com> wrote in message
news:2n***********@uni-berlin.de...
我正在寻找std的任何自定义分配器示例代码: :vector。
I am looking for any custom allocator sample code for std::vector.
http://www.josuttis.com/libbook/memo...lloc1.cpp.html
谢谢。
在该示例中,我们可以看到方法''allocate''和''deallocate''被调用。
但方法''构造''和'' destroy''没有被调用。
什么时候应该''构造''和''破坏''被调用?
-
Alex Vinokur
http://mathforum.org/library/view/10978 .html
http://sourceforge.net/users/alexvn
Thanks.
In that sample we can see that methods ''allocate'' and ''deallocate'' were invoked.
But methods ''construct'' and ''destroy'' were not invoked.
When should ''construct'' and ''destroy'' be invoked?
--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
" Alex Vinokur" <人**** @ big-foot.com>在消息中写道
news:2n ************ @ uni-berlin.de ...
"Alex Vinokur" <al****@big-foot.com> wrote in message
news:2n************@uni-berlin.de...
什么时候应该' 'construct''和''destroy''被调用?
When should ''construct'' and ''destroy'' be invoked?
分配器必须提供构造和销毁操作。您可能需要
来查看20.1.5(分配器要求)。
构造用于初始化分配有值的内存。这是
基本上是对新的展示位置的调用。因此,当在容器中创建
对象时,基本上会调用构造。
Destroy只是调用对象的析构函数。
-Sharad
An allocator has to provide a construct and destruct operation. You may want
to take a look at 20.1.5 (Allocator requirements).
Construct is used to initialize the memory allocated with a value. This is
basically a call to placement new. So basically construct is invoked when an
object is created in the container.
Destroy simply calls the destructor for the object.
-Sharad
这篇关于向量的自定义分配器示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!