• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ reserve函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: load_crashdump_segments

/* Loads additional segments in case of a panic kernel is being loaded.
 * One segment for backup region, another segment for storing elf headers
 * for crash memory image.
 */
int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline,
				unsigned long max_addr, unsigned long min_base)
{
	void *tmp;
	unsigned long sz, elfcorehdr;
	int nr_ranges, align = 1024, i;
	unsigned long long end;
	struct memory_range *mem_range;

	if (get_crash_memory_ranges(&mem_range, &nr_ranges) < 0)
		return -1;

	info->backup_src_start = BACKUP_SRC_START;
	info->backup_src_size = BACKUP_SRC_SIZE;
#ifndef CONFIG_BOOKE
	/* Create a backup region segment to store backup data*/
	sz = (BACKUP_SRC_SIZE + align - 1) & ~(align - 1);
	tmp = xmalloc(sz);
	memset(tmp, 0, sz);
	info->backup_start = add_buffer(info, tmp, sz, sz, align,
					0, max_addr, 1);
	reserve(info->backup_start, sz);
#endif

	/* On powerpc memory ranges in device-tree is denoted as start
	 * and size rather than start and end, as is the case with
	 * other architectures like i386 . Because of this when loading
	 * the memory ranges in crashdump-elf.c the filesz calculation
	 * [ end - start + 1 ] goes for a toss.
	 *
	 * To be in sync with other archs adjust the end value for
	 * every crash memory range before calling the generic function
	 */

	for (i = 0; i < nr_ranges; i++) {
		end = crash_memory_range[i].end - 1;
		crash_memory_range[i].end = end;
	}


#ifdef CONFIG_PPC64
	/* Create elf header segment and store crash image data. */
	if (arch_options.core_header_type == CORE_TYPE_ELF64) {
		if (crash_create_elf64_headers(info, &elf_info64,
					crash_memory_range, nr_ranges, &tmp,
					&sz, ELF_CORE_HEADER_ALIGN) < 0)
			return -1;
	} else if (crash_create_elf32_headers(info, &elf_info32,
				crash_memory_range, nr_ranges, &tmp, &sz,
				ELF_CORE_HEADER_ALIGN) < 0)
			return -1;
#else
	if (crash_create_elf32_headers(info, &elf_info32, crash_memory_range,
				nr_ranges, &tmp, &sz, ELF_CORE_HEADER_ALIGN)
			< 0)
		return -1;
#endif

	elfcorehdr = add_buffer(info, tmp, sz, sz, align,
			min_base, max_addr, 1);
	reserve(elfcorehdr, sz);
	/* modify and store the cmdline in a global array. This is later
	 * read by flatten_device_tree and modified if required
	 */
	add_cmdline_param(mod_cmdline, elfcorehdr, " elfcorehdr=", "K");
	add_cmdline_param(mod_cmdline, saved_max_mem, " savemaxmem=", "M");
	return 0;
}
开发者ID:chitranshi,项目名称:kexec-tools,代码行数:72,代码来源:crashdump-powerpc.c


示例17: main

int main(int argc, char **argv) {

	remove("/tp-2015-2c-signiorcodigo/swap/log_swap");

	swapConfig = config_create("/tp-2015-2c-signiorcodigo/swap/swapConfig");

	setupSwap();

	setPages();

	int socketEscucha, socketMemoria;

	char * puerto = getPort();

	socketEscucha = setup_listen("localhost", puerto);

	socketMemoria = esperarConexionEntrante(socketEscucha, 1024, log_swap);

	t_data * paqueteInicio = leer_paquete(socketMemoria);

	if (paqueteInicio->header->codigo_operacion == 1) {

		int datonulo = 0;

		paqueteInicio = pedirPaquete(2, sizeof(int), &datonulo);

		common_send(socketMemoria, paqueteInicio);

		log_info(log_swap, "Conectado con la memoria en el socket: %d",
				socketMemoria);

	} else {

		log_info(log_swap, "Falla en la conexion con la memoria");

		exit(EXIT_FAILURE);
	}

	t_data * paquete;

	while (1) {

		paquete = leer_paquete(socketMemoria);

		switch (paquete->header->codigo_operacion) {

		case LEER: {

			int pid, page;

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&page, paquete->data + sizeof(int), sizeof(int));

			char * content = readProcessPage(pid, page);

			paquete = pedirPaquete(LEER, getSwapPagesSize(), content);

			common_send(socketMemoria, paquete);

			break;
		}

		case ESCRIBIR: {

			int pid, page;
			char * content = malloc(getSwapPagesSize());

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&page, paquete->data + sizeof(int), sizeof(int));
			memcpy(content, paquete->data + 2 * sizeof(int),
					getSwapPagesSize());

			writeProcessPage(pid, page, content);

			break;
		}

		case INICIAR: {

			int pid, pagesAmount;

			memcpy(&pid, paquete->data, sizeof(int));
			memcpy(&pagesAmount, paquete->data + sizeof(int), sizeof(int));

			int blank_pages = getBlankPages();
			int success;

			if (blank_pages >= pagesAmount) {
				success = reserve(pid, pagesAmount);

				if (success == -1) {
					compact();
					success = reserve(pid, pagesAmount);
				}
			}else{
				success = -1;
			}


			if (success == -1) {
//.........这里部分代码省略.........
开发者ID:LucasFunti,项目名称:TpOperativos2015,代码行数:101,代码来源:swap.c


示例18: reserve

BinaryStreamBuffer::BinaryStreamBuffer()
{
	reserve(128);
}
开发者ID:bsumirak,项目名称:ugcore,代码行数:4,代码来源:binary_stream.cpp


示例19: main

int
main(int argc, char *argv[])
{
	const int KERNEL_NPROC = 64;
	const int CHILD_STARTUP_SLEEP = 100;
	const int MIN_UPTIME = 1000;
	if(argc!=2) {
    	printf(1, "%s", "USAGE: tester.c <int testnum>\n");
		exit();
	}
	int option = atoi(argv[1]);
	if(option == 0) {
		//SAME PERCENT RESERVE
		
		//Make this reserve 50
		int returnval = reserve(50);
		if(returnval < 0) {
			printf(1, "ERROR: reserve failed\n");
		}
		//Test 4 reserve procs with 50% reserve
		//Expect ~same number of times chosen
		const int NUM_PROC = 3;
		int pids[NUM_PROC+1];
		int chosen[NUM_PROC+1];
		int time[NUM_PROC+1];
		int charge[NUM_PROC+1];
		int i;
		int pid;
		pids[0] = getpid();
        for(i=0; i<NUM_PROC; i++) {
			pid = fork();
			if(pid == 0) {
				//child
				returnval = reserve(50);
				if(returnval < 0) {
					printf(1, "ERROR: reserve failed\n");
				}
				break;
			}
			else {
				//parent
				pids[i+1] = pid;
			}
		}
		if(pid == 0) {
			sleep(CHILD_STARTUP_SLEEP*2);
			while(1) {
			}		
		}
		else {
			while(1) {
				sleep(MIN_UPTIME);
				struct pstat p;
				struct pstat *stats = &p;
				int returnval = getpinfo(stats);
				if(returnval < 0) {
					continue;
				}
				int count = 0;
				for(i=0; i<KERNEL_NPROC; i++) {
					int j;
					for(j=0; j<NUM_PROC+1; j++) {
						if(pids[j] == stats->pid[i] || getpid() == stats->pid[i]) {
							chosen[j] = stats->chosen[i];
							time[j] = stats->time[i];
							charge[j] = stats->charge[i];
							count++;
						}
					}
				}
				for(i=0; i<NUM_PROC+1; i++) {
					//pid,chosen,time,charge
					printf(1, "%d,%d,%d,%d\n", pids[i], chosen[i], time[i], charge[i]);
				}
			}
		}
	}

	else if(option == 2) {
		//DIFF BID SPOT
		
		//Make this spot with bid 50
		int returnval;
		returnval = spot(50);
		if(returnval < 0) {
			printf(1, "ERROR: spot failed\n");
		}
		//Expect significant difference in number of times chosen between bid levels
		const int NUM_PROC = 10;
		int pids[NUM_PROC+1];
		int chosen[NUM_PROC+1];
		int time[NUM_PROC+1];
		int charge[NUM_PROC+1];
		int i;
		int pid;
		int bid = 20;
		
		pids[0] = getpid();

        for(i=0; i<NUM_PROC; i++) {
//.........这里部分代码省略.........
开发者ID:cschwalm,项目名称:CS537-P2b,代码行数:101,代码来源:tester.c


示例20: resize

	void resize(int newSize){
		if (newSize > theCapacity){
			reserve(newSize * 2 + 1);
		}
		theSize = newSize;
	}
开发者ID:daniyuu,项目名称:DataStructCplus,代码行数:6,代码来源:Vector.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ reserve_bootmem函数代码示例发布时间:2022-05-30
下一篇:
C++ reseatable函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap