C++?????????????????
???????????? ???????[ 2015/4/13 14:10:38 ] ????????C++ ??? ???? ????
??????????reallocate()???????
template <class T> void VECTOR<T>::reallocate()
{
ptrdiff_t size = first_free - elements;
ptrdiff_t newCapacity = 2 * max(size?? 1);
T *newElement = alloc.allocate(newCapacity); //???????????
uninitialized_copy(elements?? first_free?? newElement); //?????????????????
for (T *p = first_free; p != elements; ) //??????????????????????
{
alloc.destroy(--p);
}
if (elements)
{
alloc.deallocate(elements?? end - elements); //??????????
}
elements = newElement; //?????????????????
first_free = elements + size;
end = elements + newCapacity;
}
?????????????????????????????vector??STL?????????????????STL???????????飬???????????????????
????2??operator new??????operator delete????
?????????string *sp = new string("initialized");????????????裺
??????1?????????operator new???????????????????????δ?????????棬????????????????????
??????2?????и???????????????????????????????????
??????3??????????·???????????????
?????????delete sp;????????????裺
??????1????sp??????????????????????????
??????2?????????operator delete?????????????????????檔
????operator new??operator delete??????????????汾??????汾???????new??????
????void *operator new(size_t);
????void *operator new[](size_t);
????void *operator delete(size_t);
????void *operator delete[](size_t);
????????????operator new??operator delete???????????new????????????????????????е?????????????????δ???????檔???????£?
????T *newElement = alloc.allocate(newCapacity); //???????????
????T *newElement = static_cast<T*>(operator new[](sizeof(T) * newCapacity));
?????????????????????????????????????????
????alloc.deallocate(elements?? end - elements); //??????????
????operator delete[](elements);
?????????allocator??????????????棬???????????????????λ???????棬??????operator new??????????????????????????????operator new??operator delete????????
??????????????????
????C++??????????????????й???????????
??????1??allocator?????construct??destroy??
??????2????λnew??????
??????3???????????????????????????????????????????????????檔
??????4????uninitialized_copy??uninitialized_fill???????
????????????????λnew???????????????????????????
??????λnew??????????????????г?????????????????????棬????????????δ????????????????????г?????????????λnew????????????
????new (place_address) type
????new (place_address) type(initializer-list)
????????place_address????????initializer-list????????????????????б?????????£?
????alloc.construct(first_free?? t);
????new (first_free) T(t);
????string *sp = alloc.allocate(2);
????new (sp) string(b?? e);
???????
??????1????λnew?????????????????????????κι???????????????????allocator???construct?????????????????????
??????2??????????????????????????????????????п???????????????????????????塣?????Щ?????????????????????????????????????????????е?????????????????????????????????????λnew??????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????