[問題] 關於vector::get_allocator()
看了一下網路上的C++ reference上面的解釋
還是不太懂這東西的用法
vector<int> myvector;
int * p;
unsigned int i;
// allocate an array of 5 elements using vector's allocator:
p=myvector.get_allocator().allocate(5);
cout<<myvector.size();
// assign some values to array
for (i=0; i<5; i++) p[i]=i;
cout << "The allocated array contains:";
for (i=0; i<5; i++) cout << " " << p[i];
cout << endl;
myvector.get_allocator().deallocate(p,5);
我把這東西解讀成,可以使p這個指標也擁有myvector的性質?
可是基本上myvector是不會受到影響的!?(myvector.size()為0)
最後要還給系統記憶體空間的時候用delete p跟用deallocate(p,5)
會有什麼不一樣嗎?
謝謝^^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.172.243.143
※ 編輯: Arim 來自: 218.172.243.143 (08/28 23:09)
※ 編輯: Arim 來自: 218.172.243.143 (08/28 23:11)
※ 編輯: Arim 來自: 218.172.243.143 (08/28 23:18)
→
08/28 23:31, , 1F
08/28 23:31, 1F
→
08/28 23:31, , 2F
08/28 23:31, 2F
→
08/28 23:35, , 3F
08/28 23:35, 3F
→
08/28 23:35, , 4F
08/28 23:35, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章