当前位置: 首页>>代码示例>>C++>>正文


C++ reserve函数代码示例

本文整理汇总了C++中reserve函数的典型用法代码示例。如果您正苦于以下问题:C++ reserve函数的具体用法?C++ reserve怎么用?C++ reserve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了reserve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: resize

 void resize(unsigned newsize) {
   if(newsize > poolsize) reserve(bit::round(newsize));  //round reserve size up to power of 2
   buffersize = newsize;
 }
开发者ID:BadyRaty,项目名称:Mednafen-Core,代码行数:4,代码来源:array.hpp

示例2: fast_vector

 fast_vector(const fast_vector<value_type>& v) : sz_(0), n_(0), buf_(0) {
     reserve(v.n_);
     n_ = v.n_;
     std::memcpy(buf_, v.buf_, n_ * sizeof(value_type));
 } // fast_vector
开发者ID:paulkowa,项目名称:ELaSTIC,代码行数:5,代码来源:fast_vector.hpp

示例3: queue

	queue(size_t capacity = MIN_CAPACITY)
	{
		reserve(capacity > MIN_CAPACITY ? capacity : MIN_CAPACITY);
	}
开发者ID:glyredsun,项目名称:gtl,代码行数:4,代码来源:queue.hpp

示例4: push_back

void push_back( const Object & x )
{
    if( theSize == theCapacity )
        reserve( 2 * theCapacity + 1 );
    objects[ theSize++ ] = x;
}
开发者ID:hhraymond,项目名称:apple,代码行数:6,代码来源:fig03_11.cpp

示例5: throw

void StringBuffer::resize(size_t sz) throw()
{
	reserve(sz);
	m_end = sz;
}
开发者ID:clteng5316,项目名称:rodents,代码行数:5,代码来源:string.cpp

示例6: dtype

gl_sframe gl_sarray::unpack(const std::string& column_name_prefix, 
                           const std::vector<flex_type_enum>& _column_types,
                           const flexible_type& na_value, 
                           const std::vector<flexible_type>& _limit) const {
  auto column_types = _column_types;
  auto limit = _limit;
  if (dtype() != flex_type_enum::DICT && dtype() != flex_type_enum::LIST &&
      dtype() != flex_type_enum::VECTOR) {
    throw std::string("Only SArray of dict/list/array type supports unpack");
  }
  if (limit.size() > 0) {
    std::set<flex_type_enum> limit_types;
    for (const flexible_type& l : limit) limit_types.insert(l.get_type());
    if (limit_types.size() != 1) {
      throw std::string("\'limit\' contains values that are different types");
    } 
    if (dtype() != flex_type_enum::DICT && 
        *(limit_types.begin()) != flex_type_enum::INTEGER) {
      throw std::string("\'limit\' must contain integer values.");
    }
    if (std::set<flexible_type>(limit.begin(), limit.end()).size() != limit.size()) {
      throw std::string("\'limit\' contains duplicate values.");
    }
  }

  if (column_types.size() > 0) {
    if (limit.size() > 0) {
      if (limit.size() != column_types.size()) {
        throw std::string("limit and column_types do not have the same length");
      }
    } else if (dtype() == flex_type_enum::DICT) {
      throw std::string("if 'column_types' is given, 'limit' has to be provided to unpack dict type.");
    } else {
      limit.reserve(column_types.size());
      for (size_t i = 0;i < column_types.size(); ++i) limit.push_back(i);
    }
  } else {
    auto head_rows = head(100).dropna();
    std::vector<size_t> lengths(head_rows.size());
    for (size_t i = 0;i < head_rows.size(); ++i) lengths[i] = head_rows[i].size();
    if (lengths.size() == 0 || *std::max_element(lengths.begin(), lengths.end()) == 0) {
      throw std::string("Cannot infer number of items from the SArray, "
                        "SArray may be empty. please explicitly provide column types");
    }
    if (dtype() != flex_type_enum::DICT) {
      size_t length = *std::max_element(lengths.begin(), lengths.end());
      if (limit.size() == 0) {
        limit.resize(length);
        for (size_t i = 0;i < length; ++i) limit[i] = i;
      } else {
        length = limit.size();  
      }

      if (dtype() == flex_type_enum::VECTOR) {
        column_types.resize(length, flex_type_enum::FLOAT);
      } else {
        column_types.clear();
        for(const auto& i : limit) {
          std::vector<flexible_type> f;
          for (size_t j = 0;j < head_rows.size(); ++j) {
            auto x = head_rows[j];
            if (x != flex_type_enum::UNDEFINED && x.size() > i) {
              f.push_back(x.array_at(i));
            }
          }
          column_types.push_back(infer_type_of_list(f));
        }
      }

    }
  }
  if (dtype() == flex_type_enum::DICT && column_types.size() == 0) {
    return get_proxy()->unpack_dict(column_name_prefix,
                                 limit,
                                 na_value);
  } else {
    return get_proxy()->unpack(column_name_prefix,
                            limit,
                            column_types,
                            na_value);
  } 
}
开发者ID:pauldevos,项目名称:SFrame,代码行数:82,代码来源:gl_sarray.cpp

示例7: _type

	primitive_builder::primitive_builder(primitive_type type, size_t size)
		: _type(type)
	{ reserve(size); }
开发者ID:Botyto,项目名称:Core,代码行数:3,代码来源:vertex_data.cpp

示例8: reserve

// throws runtime_error
memory_ptr memory_map::reserve(size_t size)
{
    return reserve(size, expansion_);
}
开发者ID:pmienk,项目名称:libbitcoin-database,代码行数:5,代码来源:memory_map.cpp

示例9: reserve

 void SparseStorage<DataType>::reserve(int nnz) {
   reserve(nnz, sparsity_.size2());
 }
开发者ID:tmmsartor,项目名称:casadi,代码行数:3,代码来源:sparse_storage_impl.hpp

示例10: if

void QV8Worker::serialize(QByteArray &data, v8::Handle<v8::Value> v, QV8Engine *engine)
{
    if (v.IsEmpty()) {
    } else if (v->IsUndefined()) {
        push(data, valueheader(WorkerUndefined));
    } else if (v->IsNull()) {
        push(data, valueheader(WorkerNull));
    } else if (v->IsTrue()) {
        push(data, valueheader(WorkerTrue));
    } else if (v->IsFalse()) {
        push(data, valueheader(WorkerFalse));
    } else if (v->IsString()) {
        v8::Handle<v8::String> string = v->ToString();
        int length = string->Length() + 1;
        if (length > 0xFFFFFF) {
            push(data, valueheader(WorkerUndefined));
            return;
        }
        int utf16size = ALIGN(length * sizeof(uint16_t));

        reserve(data, utf16size + sizeof(quint32));
        push(data, valueheader(WorkerString, length));
        
        int offset = data.size();
        data.resize(data.size() + utf16size);
        char *buffer = data.data() + offset;

        string->Write((uint16_t*)buffer);
    } else if (v->IsFunction()) {
        // XXX TODO: Implement passing function objects between the main and
        // worker scripts
        push(data, valueheader(WorkerUndefined));
    } else if (v->IsArray()) {
        v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(v);
        uint32_t length = array->Length();
        if (length > 0xFFFFFF) {
            push(data, valueheader(WorkerUndefined));
            return;
        }
        reserve(data, sizeof(quint32) + length * sizeof(quint32));
        push(data, valueheader(WorkerArray, length));
        for (uint32_t ii = 0; ii < length; ++ii)
            serialize(data, array->Get(ii), engine);
    } else if (v->IsInt32()) {
        reserve(data, 2 * sizeof(quint32));
        push(data, valueheader(WorkerInt32));
        push(data, (quint32)v->Int32Value());
    } else if (v->IsUint32()) {
        reserve(data, 2 * sizeof(quint32));
        push(data, valueheader(WorkerUint32));
        push(data, v->Uint32Value());
    } else if (v->IsNumber()) {
        reserve(data, sizeof(quint32) + sizeof(double));
        push(data, valueheader(WorkerNumber));
        push(data, v->NumberValue());
    } else if (v->IsDate()) {
        reserve(data, sizeof(quint32) + sizeof(double));
        push(data, valueheader(WorkerDate));
        push(data, v8::Handle<v8::Date>::Cast(v)->NumberValue());
    } else if (v->IsRegExp()) {
        v8::Handle<v8::RegExp> regexp = v8::Handle<v8::RegExp>::Cast(v);
        quint32 flags = regexp->GetFlags();
        v8::Local<v8::String> source = regexp->GetSource();

        int length = source->Length() + 1;
        if (length > 0xFFFFFF) {
            push(data, valueheader(WorkerUndefined));
            return;
        }
        int utf16size = ALIGN(length * sizeof(uint16_t));

        reserve(data, sizeof(quint32) + utf16size);
        push(data, valueheader(WorkerRegexp, flags));
        push(data, (quint32)length);
        int offset = data.size();
        data.resize(data.size() + utf16size);
        char *buffer = data.data() + offset;

        source->Write((uint16_t*)buffer);
    } else if (v->IsObject() && !v->ToObject()->GetExternalResource()) {
        v8::Handle<v8::Object> object = v->ToObject();
        v8::Local<v8::Array> properties = engine->getOwnPropertyNames(object);
        quint32 length = properties->Length();
        if (length > 0xFFFFFF) {
            push(data, valueheader(WorkerUndefined));
            return;
        }
        push(data, valueheader(WorkerObject, length));
        v8::TryCatch tc;
        for (quint32 ii = 0; ii < length; ++ii) {
            v8::Local<v8::String> str = properties->Get(ii)->ToString();
            serialize(data, str, engine);

            v8::Local<v8::Value> val = object->Get(str);
            if (tc.HasCaught()) {
                serialize(data, v8::Undefined(), engine);
                tc.Reset();
            } else {
                serialize(data, val, engine);
            }
//.........这里部分代码省略.........
开发者ID:yinyunqiao,项目名称:qtdeclarative,代码行数:101,代码来源:qv8worker.cpp

示例11: TORRENT_ASSERT_VAL

	void* packet_buffer::insert(index_type idx, void* value)
	{
		INVARIANT_CHECK;

		TORRENT_ASSERT_VAL(idx <= 0xffff, idx);
		// you're not allowed to insert NULLs!
		TORRENT_ASSERT(value);

		if (value == 0) return remove(idx);

		if (m_size != 0)
		{
			if (compare_less_wrap(idx, m_first, 0xffff))
			{
				// Index comes before m_first. If we have room, we can simply
				// adjust m_first backward.

				std::size_t free_space = 0;

				for (index_type i = (m_first - 1) & (m_capacity - 1);
						i != (m_first & (m_capacity - 1)); i = (i - 1) & (m_capacity - 1))
				{
					if (m_storage[i & (m_capacity - 1)])
						break;
					++free_space;
				}

				if (((m_first - idx) & 0xffff) > free_space)
					reserve(((m_first - idx) & 0xffff) + m_capacity - free_space);

				m_first = idx;
			}
			else if (idx >= m_first + m_capacity)
			{
				reserve(idx - m_first + 1);
			}
			else if (idx < m_first)
			{
				// We have wrapped.
				if (idx >= ((m_first + m_capacity) & 0xffff) && m_capacity < 0xffff)
				{
					reserve(m_capacity + (idx + 1 - ((m_first + m_capacity) & 0xffff)));
				}
			}
			if (compare_less_wrap(m_last, (idx + 1) & 0xffff, 0xffff))
				m_last = (idx + 1) & 0xffff;
		}
		else
		{
			m_first = idx;
			m_last = (idx + 1) & 0xffff;
		}

		if (m_capacity == 0) reserve(16);

		void* old_value = m_storage[idx & (m_capacity - 1)];
		m_storage[idx & (m_capacity - 1)] = value;

		if (m_size == 0) m_first = idx;
		// if we're just replacing an old value, the number
		// of elements in the buffer doesn't actually increase
		if (old_value == 0) ++m_size;

		TORRENT_ASSERT_VAL(m_first <= 0xffff, m_first);
		return old_value;
	}
开发者ID:EricMyers47,项目名称:OpenSpace,代码行数:66,代码来源:packet_buffer.cpp

示例12: ceil

void Vector<T>::resize(unsigned int size) {
	Log = ceil(log((double) size) / log(2.0));
	reserve(1 << Log);
	_size = size;
}
开发者ID:shashank-vishnoi,项目名称:my_project,代码行数:5,代码来源:vector_imp.cpp

示例13: ReadError

bool ccPolyline::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
	if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags))
		return false;

	if (dataVersion<28)
		return false;

	//as the associated cloud (=vertices) can't be saved directly (as it may be shared by multiple polylines)
	//we only store its unique ID (dataVersion>=28) --> we hope we will find it at loading time (i.e. this
	//is the responsibility of the caller to make sure that all dependencies are saved together)
	uint32_t vertUniqueID = 0;
	if (in.read((char*)&vertUniqueID,4) < 0)
		return ReadError();
	//[DIRTY] WARNING: temporarily, we set the vertices unique ID in the 'm_associatedCloud' pointer!!!
	*(uint32_t*)(&m_theAssociatedCloud) = vertUniqueID;

	//number of points (references to) (dataVersion>=28)
	uint32_t pointCount = 0;
	if (in.read((char*)&pointCount,4) < 0)
		return ReadError();
	if (!reserve(pointCount))
		return false;

	//points (references to) (dataVersion>=28)
	for (uint32_t i=0; i<pointCount; ++i)
	{
		uint32_t pointIndex = 0;
		if (in.read((char*)&pointIndex,4) < 0)
			return ReadError();
		addPointIndex(pointIndex);
	}

	//'global shift & scale' (dataVersion>=39)
	if (dataVersion >= 39)
	{
		if (!loadShiftInfoFromFile(in))
			return ReadError();
	}
	else
	{
		m_globalScale = 1.0;
		m_globalShift = CCVector3d(0,0,0);
	}

	QDataStream inStream(&in);

	//Closing state (dataVersion>=28)
	inStream >> m_isClosed;

	//RGB Color (dataVersion>=28)
	inStream >> m_rgbColor.r;
	inStream >> m_rgbColor.g;
	inStream >> m_rgbColor.b;

	//2D mode (dataVersion>=28)
	inStream >> m_mode2D;

	//Foreground mode (dataVersion>=28)
	inStream >> m_foreground;

	//Width of the line (dataVersion>=31)
	if (dataVersion >= 31)
		ccSerializationHelper::CoordsFromDataStream(inStream,flags,&m_width,1);
	else
		m_width = 0;

	return true;
}
开发者ID:Sephrimoth,项目名称:trunk,代码行数:69,代码来源:ccPolyline.cpp

示例14: get_devtree_details

/* Get devtree details and create exclude_range array
 * Also create usablemem_ranges for KEXEC_ON_CRASH
 */
static int get_devtree_details(unsigned long kexec_flags)
{
	uint64_t rmo_base;
	uint64_t tce_base;
	unsigned int tce_size;
	uint64_t htab_base, htab_size;
	uint64_t kernel_end;
	uint64_t initrd_start, initrd_end;
	char buf[MAXBYTES];
	char device_tree[256] = "/proc/device-tree/";
	char fname[256];
	DIR *dir, *cdir;
	FILE *file;
	struct dirent *dentry;
	struct stat fstat;
	int n, i = 0;

	if ((dir = opendir(device_tree)) == NULL) {
		perror(device_tree);
		return -1;
	}

	while ((dentry = readdir(dir)) != NULL) {
		if (strncmp(dentry->d_name, "chosen", 6) &&
			strncmp(dentry->d_name, "[email protected]", 7) &&
			strcmp(dentry->d_name, "memory") &&
			strncmp(dentry->d_name, "[email protected]", 4) &&
			strncmp(dentry->d_name, "rtas", 4))
			continue;
		strcpy(fname, device_tree);
		strcat(fname, dentry->d_name);
		if ((cdir = opendir(fname)) == NULL) {
			perror(fname);
			goto error_opendir;
		}

		if (strncmp(dentry->d_name, "chosen", 6) == 0) {
			strcat(fname, "/linux,kernel-end");
			if ((file = fopen(fname, "r")) == NULL) {
				perror(fname);
				goto error_opencdir;
			}
			if (fread(&kernel_end, sizeof(uint64_t), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
			}
			fclose(file);

			/* Add kernel memory to exclude_range */
			exclude_range[i].start = 0x0UL;
			exclude_range[i].end = kernel_end;
			i++;

			if (kexec_flags & KEXEC_ON_CRASH) {
				memset(fname, 0, sizeof(fname));
				strcpy(fname, device_tree);
				strcat(fname, dentry->d_name);
				strcat(fname, "/linux,crashkernel-base");
				if ((file = fopen(fname, "r")) == NULL) {
					perror(fname);
					goto error_opencdir;
				}
				if (fread(&crash_base, sizeof(uint64_t), 1,
						file) != 1) {
					perror(fname);
					goto error_openfile;
				}
				fclose(file);

				memset(fname, 0, sizeof(fname));
				strcpy(fname, device_tree);
				strcat(fname, dentry->d_name);
				strcat(fname, "/linux,crashkernel-size");
				if ((file = fopen(fname, "r")) == NULL) {
					perror(fname);
					goto error_opencdir;
				}
				if (fread(&crash_size, sizeof(uint64_t), 1,
						file) != 1) {
					perror(fname);
					goto error_openfile;
				}

				if (crash_base > mem_min)
					mem_min = crash_base;
				if (crash_base + crash_size < mem_max)
					mem_max = crash_base + crash_size;

				add_usable_mem_rgns(0, crash_base + crash_size);
				reserve(KDUMP_BACKUP_LIMIT, crash_base-KDUMP_BACKUP_LIMIT);
			}

			memset(fname, 0, sizeof(fname));
			strcpy(fname, device_tree);
			strcat(fname, dentry->d_name);
			strcat(fname, "/linux,htab-base");
			if ((file = fopen(fname, "r")) == NULL) {
//.........这里部分代码省略.........
开发者ID:OPSF,项目名称:uClinux,代码行数:101,代码来源:kexec-ppc64.c

示例15: reserve

QPolygonF::QPolygonF(const QPolygon &a)
{
    reserve(a.size());
    for (int i=0; i<a.size(); ++i)
        append(a.at(i));
}
开发者ID:fluxer,项目名称:katie,代码行数:6,代码来源:qpolygon.cpp


注:本文中的reserve函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。