#include
#include
using namespace std;
int main ()
{
ios::sync_with_stdio (false);
//alloc can malloc string space
allocator
alloc;
//n as capability
int n = 12;
//p as a pointer point to the first address of the space
//like begin()
auto p = alloc.allocate (n);
//q point to the address after the last element like end()
auto q = p;
alloc.construct (q++, "Fuck the world");
alloc.construct (q++, 10, 'f'); //means ffffffffff
alloc.construct (q++); //empty string
while (q != p)
alloc.destroy (--q); //we can only destroy the element really be there
//we must destroy every elements before we deallocate that
alloc.deallocate (p, n); //n must equal we allocate before
return 0;
}
allocator 的用法
最新推荐文章于 2020-08-27 20:30:58 发布