C++?????????????????
???????????? ???????[ 2015/4/13 14:10:38 ] ????????C++ ??? ???? ????
??????C++?У??????????new(delete)???????????????????new???????????????????棬?????·????????й????????????????new??????????к????????????????????????????????????????new??????????????????????????
??????????????????????????????????????????????????????棬?????????????????й????????????????????????????????У????????????????
??????1????????????????????????????????????????
??????2?????????????????????????????????????????????
????string* pstr = new string[5];
??????????????????????????????????vector<string>?????棩????????????????5??string??????string????????????????????????????????pstr[0...4]????????????new???????????????????????????????????????Щ????????????????????????Щ?????????????????????????????????棬?????????????????й???????????
????????????????
????C++?????????????????δ?????????棺
??????1??allocator??????????????????????????????????????????沢?????????汣?????
??????2????????е?operator new??operator delete??????????????????С???????δ?????????檔
????1??allocator??
????allocator?????????壬????????????????????????????????????????????£?
????allocator????????????????????allocator?????????????????????????С?????г?????????????????????????????δ????????allocator???????????construct??destroy???????????е????
????vector?????????????????vector????????????????????????????????????????Щ?????????????????????????????????????allocator???????????a?????STL vector?е?push_back??????
template <class T> class VECTOR
{
public:
VECTOR() : elements(NULL)?? first_free(NULL)?? end(NULL){}
void push_back(const T&);
private:
static allocator<T> alloc;
void reallocate();
T *elements;
T *first_free;
T *end;
};
????elements??????????????????first_free??????????????????????????end????????鱾???????????????????????????????????
template <class T> void VECTOR<T>::push_back(const T& t)
{
if (first_free == end) //???????п?????
{
reallocate(); //??????????????????
}
alloc.construct(first_free?? t); //?????????
++first_free;
}
??????
???·???
??????????????????
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