(1)打开stlport 的源码了吗,我这里使用4.6.2版本,其他版本也无妨啊。
(2)进入stlport/stl目录,有木有很多_list.h,_vector.h的文件,恭喜你找对了。
(3)打开_vector.h看看吧,建议用UE或者其他IDE环境,这样方便看哦。
(4)
template <class _Tp, class _Alloc>
class _Vector_base {
public:
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type allocator_type;
_Vector_base(const _Alloc& __a)
: _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0) {
}
_Vector_base(size_t __n, const _Alloc& __a)
: _M_start(0), _M_finish(0), _M_end_of_storage(__a, 0)
{
_M_start = _M_end_of_storage.allocate(__n);
_M_finish = _M_start;
_M_end_of_storage._M_data = _M_start + __n;
_STLP_MPWFIX_TRY _STLP_MPWFIX_CATCH
}
~_Vector_base() {
if (_M_start !=0)
_M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start);
}
protected:
_Tp* _M_start;
_Tp* _M_finish;
_STLP_alloc_proxy<_Tp*, _Tp, allocator_type> _M_end_of_storage;
};
(5)
(6)
本文详细解读STLPort 4.6.2版本中Vector基类的实现细节,包括构造函数、析构函数及内部数据结构的使用。
856

被折叠的 条评论
为什么被折叠?



