示例#1
0
 void resize(unsigned newsize) {
   if(newsize > poolsize) reserve(bit::round(newsize));  //round reserve size up to power of 2
   buffersize = newsize;
 }
示例#2
0
 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
示例#3
0
文件: queue.hpp 项目: glyredsun/gtl
	queue(size_t capacity = MIN_CAPACITY)
	{
		reserve(capacity > MIN_CAPACITY ? capacity : MIN_CAPACITY);
	}
示例#4
0
void push_back( const Object & x )
{
    if( theSize == theCapacity )
        reserve( 2 * theCapacity + 1 );
    objects[ theSize++ ] = x;
}
示例#5
0
void StringBuffer::resize(size_t sz) throw()
{
	reserve(sz);
	m_end = sz;
}
示例#6
0
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);
  } 
}
示例#7
0
	primitive_builder::primitive_builder(primitive_type type, size_t size)
		: _type(type)
	{ reserve(size); }
示例#8
0
// throws runtime_error
memory_ptr memory_map::reserve(size_t size)
{
    return reserve(size, expansion_);
}
示例#9
0
 void SparseStorage<DataType>::reserve(int nnz) {
   reserve(nnz, sparsity_.size2());
 }
示例#10
0
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);
            }
        }
    } else if (engine->isQObject(v)) {
        // XXX TODO: Generalize passing objects between the main thread and worker scripts so 
        // that others can trivially plug in their elements.
        QDeclarativeListModel *lm = qobject_cast<QDeclarativeListModel *>(engine->toQObject(v));
        if (lm && lm->agent()) {
            QDeclarativeListModelWorkerAgent *agent = lm->agent();
            agent->addref();
            push(data, valueheader(WorkerListModel));
            push(data, (void *)agent);
            return;
        } 
        // No other QObject's are allowed to be sent
        push(data, valueheader(WorkerUndefined));
    } else {
        push(data, valueheader(WorkerUndefined));
    }
}
示例#11
0
// throws runtime_error
memory_ptr memory_map::resize(size_t size)
{
    return reserve(size, 0);
}
示例#12
0
	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;
	}
示例#13
0
void Vector<T>::resize(unsigned int size) {
	Log = ceil(log((double) size) / log(2.0));
	reserve(1 << Log);
	_size = size;
}
示例#14
0
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;
}
示例#15
0
/* 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, "memory@", 7) &&
			strcmp(dentry->d_name, "memory") &&
			strncmp(dentry->d_name, "pci@", 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) {
				closedir(cdir);
				if (errno == ENOENT) {
					/* Non LPAR */
					errno = 0;
					continue;
                                }
				perror(fname);
				goto error_opendir;
			}
			if (fread(&htab_base, sizeof(uint64_t), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
			}
			memset(fname, 0, sizeof(fname));
			strcpy(fname, device_tree);
			strcat(fname, dentry->d_name);
			strcat(fname, "/linux,htab-size");
			if ((file = fopen(fname, "r")) == NULL) {
				perror(fname);
				goto error_opencdir;
			}
			if (fread(&htab_size, sizeof(uint64_t), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
			}
			/* Add htab address to exclude_range - NON-LPAR only */
			exclude_range[i].start = htab_base;
			exclude_range[i].end = htab_base + htab_size;
			i++;

			/* reserve the initrd_start and end locations. */
			if (reuse_initrd) {
				memset(fname, 0, sizeof(fname));
				strcpy(fname, device_tree);
				strcat(fname, dentry->d_name);
				strcat(fname, "/linux,initrd-start");
				if ((file = fopen(fname, "r")) == NULL) {
					perror(fname);
					goto error_opencdir;
				}
				/* check for 4 and 8 byte initrd offset sizes */
				if (stat(fname, &fstat) != 0) {
					perror(fname);
					goto error_openfile;
				}
				if (fread(&initrd_start, fstat.st_size, 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,initrd-end");
				if ((file = fopen(fname, "r")) == NULL) {
					perror(fname);
					goto error_opencdir;
				}
				/* check for 4 and 8 byte initrd offset sizes */
				if (stat(fname, &fstat) != 0) {
					perror(fname);
					goto error_openfile;
				}
				if (fread(&initrd_end, fstat.st_size, 1, file) != 1) {
					perror(fname);
					goto error_openfile;
				}
				fclose(file);

				/* Add initrd address to exclude_range */
				exclude_range[i].start = initrd_start;
				exclude_range[i].end = initrd_end;
				i++;
			}
		} /* chosen */

		if (strncmp(dentry->d_name, "rtas", 4) == 0) {
			strcat(fname, "/linux,rtas-base");
			if ((file = fopen(fname, "r")) == NULL) {
				perror(fname);
				goto error_opencdir;
			}
			if (fread(&rtas_base, sizeof(unsigned int), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
			}
			memset(fname, 0, sizeof(fname));
			strcpy(fname, device_tree);
			strcat(fname, dentry->d_name);
			strcat(fname, "/rtas-size");
			if ((file = fopen(fname, "r")) == NULL) {
				perror(fname);
				goto error_opencdir;
			}
			if (fread(&rtas_size, sizeof(unsigned int), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
			}
			closedir(cdir);
			/* Add rtas to exclude_range */
			exclude_range[i].start = rtas_base;
			exclude_range[i].end = rtas_base + rtas_size;
			i++;
			if (kexec_flags & KEXEC_ON_CRASH)
				add_usable_mem_rgns(rtas_base, rtas_size);
		} /* rtas */

		if (!strncmp(dentry->d_name, "memory@", 7) ||
			!strcmp(dentry->d_name, "memory")) {
			strcat(fname, "/reg");
			if ((file = fopen(fname, "r")) == NULL) {
				perror(fname);
				goto error_opencdir;
			}
			if ((n = fread(buf, 1, MAXBYTES, file)) < 0) {
				perror(fname);
				goto error_openfile;
			}
			rmo_base = ((uint64_t *)buf)[0];
			rmo_top = rmo_base + ((uint64_t *)buf)[1];
			if (rmo_top > 0x30000000UL)
				rmo_top = 0x30000000UL;

			fclose(file);
			closedir(cdir);
		} /* memory */

		if (strncmp(dentry->d_name, "pci@", 4) == 0) {
			strcat(fname, "/linux,tce-base");
			if ((file = fopen(fname, "r")) == NULL) {
				closedir(cdir);
				if (errno == ENOENT) {
					/* Non LPAR */
					errno = 0;
					continue;
				}
				perror(fname);
				goto error_opendir;
			}
			if (fread(&tce_base, sizeof(uint64_t), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
				return -1;
			}
			memset(fname, 0, sizeof(fname));
			strcpy(fname, device_tree);
			strcat(fname, dentry->d_name);
			strcat(fname, "/linux,tce-size");
			if ((file = fopen(fname, "r")) == NULL) {
				perror(fname);
				goto error_opencdir;
			}
			if (fread(&tce_size, sizeof(unsigned int), 1, file) != 1) {
				perror(fname);
				goto error_openfile;
			}
			/* Add tce to exclude_range - NON-LPAR only */
			exclude_range[i].start = tce_base;
			exclude_range[i].end = tce_base + tce_size;
			i++;
			if (kexec_flags & KEXEC_ON_CRASH)
				add_usable_mem_rgns(tce_base, tce_size);
			closedir(cdir);
		} /* pci */
	}
	closedir(dir);

	nr_exclude_ranges = i;

	sort_ranges();

#ifdef DEBUG
	int k;
	for (k = 0; k < i; k++)
		fprintf(stderr, "exclude_range sorted exclude_range[%d] "
			"start:%llx, end:%llx\n", k, exclude_range[k].start,
			exclude_range[k].end);
#endif
	return 0;

error_openfile:
	fclose(file);
error_opencdir:
	closedir(cdir);
error_opendir:
	closedir(dir);
	return -1;
}
示例#16
0
文件: qpolygon.cpp 项目: fluxer/katie
QPolygonF::QPolygonF(const QPolygon &a)
{
    reserve(a.size());
    for (int i=0; i<a.size(); ++i)
        append(a.at(i));
}
示例#17
0
/* 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;
}
示例#18
0
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) {

				paquete = pedirPaquete(0, sizeof(int), &pid);
				log_info(log_swap,
						"No se pudo reservar las paginas solicitadas para el proceso con pid: %d",
						pid);

			} else {

				paquete = pedirPaquete(1, sizeof(int), &pid);
				int absolutePage = getProcessFirstPage(pid);

				int byteInicial = absolutePage * getSwapPagesSize();

				int size = pagesAmount * getSwapPagesSize();

				log_info(log_swap,
						"Se inicia el proceso %d en el byte %d con tamanio %d",
						pid, byteInicial, size);

			}

			common_send(socketMemoria, paquete);

			break;
		}

		case FINALIZAR: {

			int pid;

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

			int processSpace = getProcessReservedSpace(pid)
					* getSwapPagesSize();

			int byteInicial = getProcessFirstPage(pid) * getSwapPagesSize();

			freeSpace(pid);

			log_info(log_swap,
					"Proceso %d liberado. N° de byte inicial: %d, y tamaño en bytes: %d",
					pid, byteInicial, processSpace);

			break;
		}

		default: {

			break;
		}

		}

	}

	return 0;
}
示例#19
0
BinaryStreamBuffer::BinaryStreamBuffer()
{
	reserve(128);
}
示例#20
0
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++) {
			pid = fork();
			if(pid == 0) {
				//child
				returnval = spot(bid);
				if(returnval < 0) {
					printf(1, "ERROR: spot failed\n");
				}
				break;
			}
			else {
				//parent
				if(i==4) {
					bid+=10;
				}
				pids[i+1] = pid;
			}
		}
		if(pid == 0) {
			sleep(CHILD_STARTUP_SLEEP);
			while(1) {
			}
		}
		else {
			while(1) {
				sleep(MIN_UPTIME);
				struct pstat p;
				struct pstat *stats = &p;
				int returnval = getpinfo(stats);
				if(returnval < 0) {
					printf(1, "getpinfo failed\n");
					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]) {
							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 == 3) {
		//DIFF PERCENT RESERVE
	
		//Make this reserve with 10 percent
		int returnval;
		returnval = reserve(10);
		if(returnval < 0) {
			printf(1, "ERROR: reserve failed\n");
		}
		//Test different reservation sizes
		//Sizes are 10 (parent proc), 20, 30, 40, 50, 50
		const int NUM_PROC = 5;
		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 percent = 20;
		
		pids[0] = getpid();

        for(i=0; i<NUM_PROC; i++) {
			pid = fork();
			if(pid == 0) {
				//child
				returnval = reserve(percent);
				if(returnval < 0) {
					printf(1, "ERROR: spot failed\n");
				}
				break;
			}
			else {
				//parent
				if(i<NUM_PROC-2) {
					percent+=10;
				}
				pids[i+1] = pid;
			}
		}
		if(pid == 0) {
			sleep(CHILD_STARTUP_SLEEP);
			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;
					//Find pid in pstat
					for(j=0; j<NUM_PROC+1; j++) {
						if(pids[j] == 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 == 4) {
		//RESERVE CALL TOO LOW


		//Test user attempting to reserve a percentage < 0
		//Expect -1 to be returned from the reserve call
		int flag = reserve(-1);
		if(flag < 0) {
			printf(1, "Test succeeded, reserve call failed.\n");
		}
		else {
			printf(1, "ERROR: test failed. Reserve call did not fail when percentage < 0 was input.");
		}
		exit();
	}
	else if(option == 5) {
		//RESERVE CALL TOO HIGH

		//Test user attempting to reserve a percentage > 100
		//Expect -1 to be returned from the reserve call
		int flag = reserve(101);
		if(flag < 0) {
			printf(1, "Test succeeded, reserve call failed.\n");
		}
		else {
			printf(1, "ERROR: test failed. Reserve call did not fail when a percantage > 100 was input.");
		}
		exit();
	}
	else if(option == 6) {
		//RESERVE SUM TOO HIGH

		//Make this reserve of 100
		int returnval = reserve(100);
		if(returnval < 0) {
			printf(1, "ERROR: reserve failed\n");
		}
		//Test user attempting to reserve too much cpu (currentreservation + newreservation > 200)
		//Expect -1 to be returned from second child's reserve call
		const int NUM_PROC = 2;
		int pids[NUM_PROC];
		int i;
		int pid;
        for(i=0; i<NUM_PROC; i++) {
			pid = fork();
			if(pid == 0) {
				//child
				int flag = reserve(100);
				if(i==0 && flag < 0) {
					printf(1, "ERROR: incorrect reserve failed\n");
				}
				if(i==1 && flag < 0) {
					printf(1, "Test succeeded, reserve call failed.\n");
				}
				else if(i==1) {
					printf(1, "ERROR: test failed. Reserve call did not fail when the total process percent exceeded 200.");
				}
				break;
			}
			else {
				pids[i] = pid;
				sleep(100);
			}
		}
		if(pid == 0) {
			while(1);
		}
		else {
			sleep(500);
			for(i=0; i<NUM_PROC; i++) { 
				kill(pids[i]);
				wait();
			}
			exit();
		}
	}

	else if(option == 7) {
		//CHARGE TEST

		//Make this reserve with 100
		int returnval = reserve(100);
		if(returnval < 0) {
			printf(1,"ERROR: spot call failed\n");
		}
		//Test charge in dollars
		//Expecting time*bid/nanodollars = charge
		//NOTE: ADD 10 to time and 1 to chosen to insure no error
		struct pstat p;
		struct pstat *stats = &p;
        //returnval = getpinfo(stats);
		int prevchosen = 0;
		int prevtime = 0;
		int i;
		int pid = fork();
		if(pid == 0) {
			returnval = spot(100);
			if(returnval < 0) {
				printf(1,"ERROR: reserve call failed\n");
			}
			while(1) {
			}
		}
		sleep(MIN_UPTIME);
		returnval = getpinfo(stats);
		if(returnval >= 0) {
			for(i=0; i<KERNEL_NPROC; i++) {
				if(pid == stats->pid[i]) {
					printf(1, "%d,%d,%d,%d\n", stats->pid[i], stats->chosen[i]-prevchosen, stats->time[i]-prevtime, stats->charge[i]);
				}
			}
		}
		else {
			printf(1, "ERROR: getpinfo failed\n");
		}
		while(1);
	}
	else if(option == 9) {
		//STARVATION TEST EXTRA CREDIT

		int returnval = reserve(100);
		if(returnval < 0) {
			printf(1, "ERROR: reserve failed\n");
		}
		//Test starvation
		//Expect ~same number of times chosen
		const int NUM_PROC = 4;
		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
				if(i==0) {
					returnval = reserve(100);
					if(returnval < 0) {
						printf(1, "ERROR: reserve failed\n");
					}
				}
				else {
					returnval = spot(100);
					if(returnval < 0) {
						printf(1, "ERROR: reserve failed\n");
					}
				}
				break;
			}
			else {
				//parent
				if(i==0) {
					sleep(20);
				}
				pids[i+1] = pid;
			}
		}
		if(pid == 0) {
			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]);
				}
			}
		}
	}
	return 0;
}
示例#21
0
	void resize(int newSize){
		if (newSize > theCapacity){
			reserve(newSize * 2 + 1);
		}
		theSize = newSize;
	}
void
exit_handler_intel_x64::unittest_1002_containers_vector() const
{
    auto myvector = std::vector<int>({0, 1, 2, 3});
    auto myvector2 = std::vector<int>({0, 1, 2, 3});

    auto total = 0;
    for (auto iter = myvector.begin(); iter != myvector.end(); iter++)
        total += *iter;

    auto rtotal = 0;
    for (auto iter = myvector.rbegin(); iter != myvector.rend(); iter++)
        rtotal += *iter;

    auto ctotal = 0;
    for (auto iter = myvector.cbegin(); iter != myvector.cend(); iter++)
        ctotal += *iter;

    auto crtotal = 0;
    for (auto iter = myvector.crbegin(); iter != myvector.crend(); iter++)
        crtotal += *iter;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(myvector.size() == 4);
    expect_true(myvector.max_size() >= 4);
    myvector.resize(4);
    expect_true(myvector.capacity() >= 4);
    expect_false(myvector.empty());
    myvector.reserve(4);
    myvector.shrink_to_fit();

    expect_true(myvector.at(0) == 0);
    expect_true(myvector.at(3) == 3);
    expect_true(myvector.front() == 0);
    expect_true(myvector.back() == 3);
    expect_true(myvector.data() != nullptr);

    myvector.assign(4, 0);
    myvector = myvector2;

    myvector.push_back(4);
    myvector.pop_back();
    myvector = myvector2;

    myvector.insert(myvector.begin(), 0);
    myvector.erase(myvector.begin());
    myvector = myvector2;

    myvector.swap(myvector2);
    std::swap(myvector, myvector2);

    myvector.emplace(myvector.begin());
    myvector.emplace_back();
    myvector = myvector2;

    expect_true(myvector == myvector2);
    expect_false(myvector != myvector2);
    expect_false(myvector < myvector2);
    expect_false(myvector > myvector2);
    expect_true(myvector <= myvector2);
    expect_true(myvector >= myvector2);
    myvector = myvector2;

    myvector.get_allocator();
    myvector.clear();
}
示例#23
0
void StringBuffer::append(WCHAR c) throw()
{
	reserve(m_end + 1);
	m_buffer[m_end] = c;
	++m_end;
}
示例#24
0
 /// append an item to this Array
 void append(const_reference_type item) throw() {
     const unsigned old_len(num_used_slots);
     reserve(old_len + 1, true);
     set_size(old_len + 1);
     slots[old_len] = item;
 }
示例#25
0
 explicit fast_vector(size_type n = 0) : sz_(0), n_(0), buf_(0) {
     if (n > 0) reserve(n);
     n_ = n;
 } // fast_vector
示例#26
0
 /// basic constructor
 Array(const unsigned len) throw()
  : slots(0)
  , num_slots(0)
  , num_used_slots(0) {
     reserve(len, false);
 }
 QNetworkAuthenticationCache()
 {
     setExpires(false);
     setShareable(true);
     reserve(1);
 }
示例#28
0
 //******** MANAGERS ********
 GELFILTlist(int num=16)           : vector<GELFILT *>()  { reserve(num); }
示例#29
0
Res::ResourceSet::ResourceSet(const JsonNode & node)
{
	reserve(GameConstants::RESOURCE_QUANTITY);
	for(std::string name : GameConstants::RESOURCE_NAMES)
		push_back(node[name].Float());
}
示例#30
0
void StringData::inc() {
  assert(!isStatic());
  assert(!empty());

  if (isImmutable()) {
    escalate(m_len + 1);
  } else {
    reserve(m_len + 1);
  }
  m_hash = 0;

  enum class CharKind {
    UNKNOWN,
    LOWER_CASE,
    UPPER_CASE,
    NUMERIC
  };

  auto const len = m_len;
  auto const s = m_data;
  int carry = 0;
  int pos = len - 1;
  auto last = CharKind::UNKNOWN; // Shut up the compiler warning
  int ch;

  while (pos >= 0) {
    ch = s[pos];
    if (ch >= 'a' && ch <= 'z') {
      if (ch == 'z') {
        s[pos] = 'a';
        carry=1;
      } else {
        s[pos]++;
        carry=0;
      }
      last = CharKind::LOWER_CASE;
    } else if (ch >= 'A' && ch <= 'Z') {
      if (ch == 'Z') {
        s[pos] = 'A';
        carry=1;
      } else {
        s[pos]++;
        carry=0;
      }
      last = CharKind::UPPER_CASE;
    } else if (ch >= '0' && ch <= '9') {
      if (ch == '9') {
        s[pos] = '0';
        carry=1;
      } else {
        s[pos]++;
        carry=0;
      }
      last = CharKind::NUMERIC;
    } else {
      carry=0;
      break;
    }
    if (carry == 0) {
      break;
    }
    pos--;
  }

  if (carry) {
    if (UNLIKELY(len + 1 > MaxSize)) {
      throw InvalidArgumentException("len > 2^31-2", len);
    }

    assert(len + 2 <= capacity());
    memmove(s + 1, s, len);
    s[len + 1] = '\0';
    m_len = len + 1;

    switch (last) {
    case CharKind::NUMERIC:
      s[0] = '1';
      break;
    case CharKind::UPPER_CASE:
      s[0] = 'A';
      break;
    case CharKind::LOWER_CASE:
      s[0] = 'a';
      break;
    default:
      break;
    }
  }
}