OSCL_EXPORT_REF void Oscl_Vector_Base::assign_vector(const Oscl_Vector_Base& x)
{
    if (x.size() > capacity())
    {
        // allocate space and copy
        OsclAny* tmp = pOpaqueType->allocate((uint32)x.end() - (uint32)x.begin());
        uninitialized_copy(x.begin(), x.end(), tmp);
        destroy(begin(), end());
        if (elems)
            pOpaqueType->deallocate(elems);
        elems = tmp;
        bufsize = x.size();
    }
    else if (size() >= x.size())
    {
        OsclAny* i = copy(x.begin(), x.end(), begin());
        destroy(i, end());
    }
    else
    {
        copy(x.begin(), increment_T(x.begin(), size()), begin());
        uninitialized_copy(increment_T(x.begin(), size()), x.end(), end());
    }
    numelems = x.size();
}
Exemplo n.º 2
0
void 
__vector__<_Tp, _Alloc>::_M_assign_aux(_ForwardIter __first, _ForwardIter __last,
				   forward_iterator_tag) {
  size_type __len = 0;
  distance(__first, __last, __len);
    
  if (__len > capacity()) {
    iterator __tmp = _M_allocate_and_copy(__len, __first, __last);
    _Destroy(_M_start, _M_finish);
    _M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start);
    _M_start = __tmp;
    _M_end_of_storage._M_data = _M_finish = _M_start + __len;
  }
  else if (size() >= __len) {
    iterator __new_finish = copy(__first, __last, _M_start);
    _Destroy(__new_finish, _M_finish);
    _M_finish = __new_finish;
  }
  else {
    _ForwardIter __mid = __first;
    advance(__mid, size());
    copy(__first, __mid, _M_start);
    _M_finish = uninitialized_copy(__mid, __last, _M_finish);
  }
}
Exemplo n.º 3
0
// Change the string's capacity so that it is large enough to hold
//  at least __res_arg elements, plus the terminating _CharT().  Note that,
//  if __res_arg < capacity(), this member function may actually decrease
//  the string's capacity.
template <class _CharT, class _Traits, class _Alloc> void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type __res_arg) {

  if (__res_arg >= capacity())
    {      
      if (__res_arg > max_size())
	this->_M_throw_length_error();

      size_type __n = __res_arg + 1;
      pointer __new_start = this->_M_end_of_storage.allocate(__n);
      pointer __new_finish = __new_start;
      
      _STLP_TRY {
	__new_finish = uninitialized_copy(this->_M_start, this->_M_finish, __new_start);
	_M_construct_null(__new_finish);
      }
      _STLP_UNWIND((_STLP_STD::_Destroy(__new_start, __new_finish), 
		    this->_M_end_of_storage.deallocate(__new_start, __n)));
      
      _STLP_STD::_Destroy(this->_M_start, this->_M_finish + 1);
      this->_M_deallocate_block();
      this->_M_start = __new_start;
      this->_M_finish = __new_finish;
      this->_M_end_of_storage._M_data = __new_start + __n;
    }
}
OSCL_EXPORT_REF void Oscl_Vector_Base::construct(Oscl_Opaque_Type_Alloc* aType, const Oscl_Vector_Base& x)
{
    numelems = x.numelems;
    bufsize = x.numelems;//only enough for current elements
    pOpaqueType = aType;
    elems = pOpaqueType->allocate(bufsize * sizeof_T);
    uninitialized_copy(x.begin(), x.end(), begin());
}
Exemplo n.º 5
0
		// Create(it,it)
		template<class T> void vec<T>::create(iterator beg, iterator end)
		{
			//get size of memory to be allocated and allocate
			ptrdiff_t size = end - begin;
			data = memManage.allocate(size);
			//Initilize memory with data delimited by iterators
			endData = uninitialized_copy(begin,end,data);
			limit = endData;
		}
Exemplo n.º 6
0
        std::pair<std::string *, std::string *>
            alloc_and_copy(const std::string *begin, const std::string *end)
            {
                // allocate `unconstructed` space to hold elements
                // *cxx-iter-arithmetic*
                auto data = alloc.allocate(end - begin);

                // uninitialized_copy() 
                // * construct copies of given elements in uninitialized space
                // * returns the position after the last initialized element.
                return {data, uninitialized_copy(begin, end, data)};
            }
Exemplo n.º 7
0
template<class T> void Vec<T>::grow() {
    // when growing, allocate twice as much space as currently in use
    size_type new_size = max(2 * (limit - data), std::ptrdiff_t(1));

    // allocate new space and copy existing elements to the new space
    iterator new_data = alloc.allocate(new_size);
    iterator new_avail = uninitialized_copy(data, avail, new_data);

    // return the old space
    uncreate();

    // reset pointers to point to the newly allocated space
    data = new_data;
    avail = new_avail;
    limit = data + new_size;
}
Exemplo n.º 8
0
void  __vector__<_Tp, _Alloc>::_M_range_insert(
					   __iterator__ __position,
					   _ForwardIterator __first,
					   _ForwardIterator __last,
					   forward_iterator_tag)
# endif /* MEMBER_TEMPLATES */

# if !( defined ( __STL_MEMBER_TEMPLATES ) &&  defined (__STL_INLINE_MEMBER_TEMPLATES))
{
  if (__first != __last) {
    size_type __n = 0;
    distance(__first, __last, __n);
    if (size_type(_M_end_of_storage._M_data - _M_finish) >= __n) {
      const size_type __elems_after = _M_finish - __position;
      pointer __old_finish = _M_finish;
      if (__elems_after > __n) {
          uninitialized_copy(_M_finish - __n, _M_finish, _M_finish);
          _M_finish += __n;
          copy_backward(__position, __old_finish - __n, __old_finish);
          copy(__first, __last, __position);
      }
      else {
# if (defined ( __STL_MEMBER_TEMPLATES ) && ! defined (__STL_INLINE_MEMBER_TEMPLATES))
          _ForwardIterator __mid = __first;
          advance(__mid, __elems_after);
# else
          __const_pointer__ __mid = __first + __elems_after;
# endif
          uninitialized_copy(__mid, __last, _M_finish);
          _M_finish += __n - __elems_after;
          uninitialized_copy(__position, __old_finish, _M_finish);
          _M_finish += __elems_after;
          copy(__first, __mid, __position);
      }
    }
    else {
      const size_type __old_size = size();
      const size_type __len = __old_size + max(__old_size, __n);
      pointer __new_start = _M_end_of_storage.allocate(__len);
      pointer __new_finish = __new_start;
      __STL_TRY {
	__new_finish = uninitialized_copy(_M_start, __position, __new_start);
	__new_finish = uninitialized_copy(__first, __last, __new_finish);
	__new_finish
	  = uninitialized_copy(__position, _M_finish, __new_finish);
      }
      __STL_UNWIND((_Destroy(__new_start,__new_finish), 
		    _M_end_of_storage.deallocate(__new_start,__len)));
      _Destroy(_M_start, _M_finish);
      _M_end_of_storage.deallocate(_M_start, _M_end_of_storage._M_data - _M_start);
      _M_start = __new_start;
      _M_finish = __new_finish;
      _M_end_of_storage._M_data = __new_start + __len;
    }
  }
Exemplo n.º 9
0
void String::reallocate()
{
    auto newcapacity = size() ? size()*2 : 1;

    // auto new_data = alloc.allocate(newcapacity);
    // auto dest = new_data;
    // auto elem = elements;
    // for(size_t i=0; i !=size(); i++){
    // 	alloc.construct(dest++, std::move(*elem++));
    // }
    auto first = alloc.allocate(newcapacity);
    auto last = uninitialized_copy(make_move_iterator(begin()), make_move_iterator(end()), first);
    free();
    // elements = new_data;
    // first_free = dest;
    elements = first;
    first_free = last;
    cap = elements + newcapacity;
}
Exemplo n.º 10
0
		//grow
		template<class T> void vec<T>::grow()
		{
			//To ensure low overhead, preallocate
			//Everytime grow request arrives, allocate tiwce the number of 
			//current mem allocated
			
			size_type new_size = max(2*(limit-data),ptrdiff_t(1));
			
			// allocate and copy data to new region
			iterator new_data = memManage.allocate(new_size);
			iterator new_endData = uninitialized_copy(data,endData,new_data);
			
			//Destroy old region
			destroy();
			
			//update iterator members
			data = new_data;
			endData = new_endData;
			limit = data + new_size;
		}
Exemplo n.º 11
0
void Vec<T>::grow()
{
	//when growing ,allocate twice as much space as currently in use
	//策略,每次分配时,都分配双倍的空间,当然vec当前可能为空,因为我们可以选择一个元素的空间和已有空间的2倍来比较大小。
	//由于max的2个参数必须类型相同,所有我们显式构造了ptr_diff(1)
	size_type new_size=max(2*(limit-data),ptrdiff_t(1));

	/**
	 我们首先把要分配多少元素的空间保存在new_size中,接下来分配适当大小的空间,并且调用uninitialze_copy把当前空间的元素,复制到新
	 空间中,然后调用uncreate函数来释放原先的内存,最后我们重新设置指针的值。
	 **/
	iterator new_data=alloc.allocate(new_size);
	iterator new_avail=uninitialized_copy(data,avail,new_data);

	uncreate();

	//reset pointer
	data=new_data;
	avail=new_avail;
	limit=data+new_size;
}
Exemplo n.º 12
0
void Vec<T>::create(const_iterator i, const_iterator j) {
    data = alloc.allocate(j-i);
    limit = avail = uninitialized_copy(i, j, data);
}
Exemplo n.º 13
0
pair<char*, char*> String::alloc_n_copy(const char *b, const char *e)
{
    auto data = alloc.allocate(e - b);
    return {data, uninitialized_copy(b, e, data)};
}
Exemplo n.º 14
0
pair<string *, string *> StrVec::alloc_n_copy(const string * b, const string * e) 
{	
	// allocate space to hold as many elements as are in the range
	auto data = alloc.allocate(e - b);
	return{data, uninitialized_copy(b, e, data)};
}
Exemplo n.º 15
0
std::pair<std::string*,std::string*> str_vec::alloc_n_copy(std::string *b,std::string *e)
{
    std::string *p= alloc.allocate(e-b);
    return make_pair(p,uninitialized_copy(b,e,p));
}
Exemplo n.º 16
0
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
    false_type) {
    return uninitialized_copy(first, last, dest, a);
}
Exemplo n.º 17
0
pair<string * ,string *> StrVec::alloc_n_copy(const string *b, const string *e)
{
	auto data = alloc.allocate(e-b);
	return {data ,uninitialized_copy(b,e,data)};
}
Exemplo n.º 18
0
byte_array::byte_array(std::initializer_list<uint8_t> data)
{
    resize(data.size());
    uninitialized_copy(data.begin(), data.end(), value.begin());
}
Exemplo n.º 19
0
pair<char * , char *> String::alloc_n_copy(const char *b,const char *e)
{
	auto ret = alloc.allocate(e-b);
	return {ret , uninitialized_copy(b,e,ret)};
}