struct tankdef tankFromJSON(json_t* root) { size_t i; if( !json_is_object(root) ) { fprintf(stderr, "Error: root is not an object!\n"); json_decref(root); exit(1); } struct tankdef theTank; loadJSONString(theTank.name, max_size(NAME), root, "name"); loadJSONString(theTank.author, max_size(AUTHOR), root, "author"); loadJSONString(theTank.program, max_size(PROGRAM), root, "program"); loadJSONString(theTank.color, max_size(COLOR), root, "color"); json_t* sensors = json_object_get(root, "sensors"); if(!json_is_array(sensors)) { fprintf(stderr, "Error: sensors object is not an array!\n"); exit(1); } for(i=0; i<json_array_size(sensors); i++) { json_t* sensor = json_array_get(sensors, i); theTank.sensors[i] = sensorFromJSON(sensor); } return theTank; }
struct tankdef readTankFromDir(char* path) { DIR* dp; if( (dp=opendir(path))==NULL ) { perror(path); exit(1); } struct tankdef theTank; initTank(&theTank); struct dirent* files; while( (files=readdir(dp)) != NULL ) { if( isNotRealDir(files) ) { continue; } char file[1000]; sprintf(file, "%s/%s", path, files->d_name); if( isSensor(files->d_name) ) { int sensorId = files->d_name[strlen("sensor")]-'0'; theTank.sensors[sensorId] = parseSensor(file); } else if( strcmp(files->d_name, "name") == MATCH ) { loadFileContent( theTank.name, file, max_size(NAME) ); } else if( strcmp(files->d_name, "author") == MATCH ) { loadFileContent( theTank.author, file, max_size(AUTHOR) ); } else if( strcmp(files->d_name, "program") == MATCH ) { loadFileContent( theTank.program, file, max_size(PROGRAM) ); } else if( strcmp(files->d_name, "color") == MATCH ) { loadFileContent( theTank.color, file, max_size(COLOR) ); } } closedir(dp); return theTank; }
void AddHeader(const Header& h) { CHECK(!h.name.empty()); const size_t entry_size = HeaderSize(h); while (!empty() && (size() + entry_size > max_size())) { PopHeader(); } if (entry_size > max_size()) { // https://tools.ietf.org/html/rfc7541#section-4.1 // If this header is larger than the max size, clear the table only. DCHECK(empty()); return; } _size += entry_size; CHECK(!_header_queue.full()); _header_queue.push(h); const int id = _add_times++; if (_need_indexes) { // Overwrite existance value. if (!h.value.empty()) { _header_index[h] = id; } _name_index[h.name] = id; } }
void write(const T& element) { assert(mSize+1 <= max_size()); mBuffer[mWriteIndex] = element; ++mWriteIndex; if (max_size() <= mWriteIndex) mWriteIndex -= max_size(); ++mSize; }
size_t NSIDMap::size() const { for(size_t i = 0; i < max_size(); ++i) { if(not get(i)) { return i; } } return max_size(); }
template <class _CharT, class _Traits, class _Alloc> basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::append(size_type __n, _CharT __c) { if (__n > max_size() || size() > max_size() - __n) this->_M_throw_length_error(); if (size() + __n > capacity()) reserve(size() + (max)(size(), __n)); if (__n > 0) { uninitialized_fill_n(this->_M_finish + 1, __n - 1, __c); _STLP_TRY { _M_construct_null(this->_M_finish + __n); } _STLP_UNWIND(_Destroy(this->_M_finish + 1, this->_M_finish + __n)); _Traits::assign(*end(), __c); this->_M_finish += __n; }
Fixed_memory_range::Fixed_memory_range(const uintptr_t begin, const uintptr_t end, const char* name, In_use_delg in_use_operation) : name_{name} , in_use_op_{in_use_operation} { if (begin > end) { throw Memory_range_exception{"Start is larger than end: " + std::to_string(begin) + " > " + std::to_string(end)}; } if ((end - begin + 1) > static_cast<uintptr_t>(max_size())) { throw Memory_range_exception{"Maximum range size is " + std::to_string(max_size())}; } range_ = Memory_range(reinterpret_cast<uint8_t*>(begin), (end - begin + 1)); }
MemoryUsage PSGenerationPool::get_memory_usage() { size_t maxSize = (available_for_allocation() ? max_size() : 0); size_t used = used_in_bytes(); size_t committed = _old_gen->capacity_in_bytes(); return MemoryUsage(initial_size(), used, committed, maxSize); }
void pushable<T>::push_back( T const& x #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS , boost::contract::virtual_* v #endif ) { #ifndef BOOST_CONTRACT_NO_OLDS boost::contract::old_ptr<unsigned> old_capacity = BOOST_CONTRACT_OLDOF(v, capacity()); #endif #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS boost::contract::check c = boost::contract::public_function(v, this) #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([&] { BOOST_CONTRACT_ASSERT(capacity() < max_size()); }) #endif #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .postcondition([&] { BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); }) #endif ; #endif assert(false); // Shall never execute this body. }
NSIDMap::NSIDMap(NSIDMap&& in_other) { for(unsigned i = 0; i < max_size(); ++i) { push_back(std::move(in_other[i])); } }
/** * 根据统计信息调整当前线程的本地分配缓冲区的基准大小 */ void ThreadLocalAllocBuffer::resize() { if (ResizeTLAB) { //允许调整线程的本地分配缓冲区大小 // Compute the next tlab size using expected allocation amount size_t alloc = (size_t)(_allocation_fraction.average() * (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize)); size_t new_size = alloc / _target_refills; //根据本地分配缓冲区大小允许的最大值/最小值来调整缓冲区的新大小 new_size = MIN2(MAX2(new_size, min_size()), max_size()); //内存对齐后的大小 size_t aligned_new_size = align_object_size(new_size); if (PrintTLAB && Verbose) { gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", myThread(), myThread()->osthread()->thread_id(), _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); } set_desired_size(aligned_new_size); set_refill_waste_limit(initial_refill_waste_limit()); } }
//template< typename Alloc > // dynarray(size_type c, const T& v, const Alloc& alloc); //dynarray(const dynarray& d); //template< typename Alloc > // dynarray(const dynarray& d, const Alloc& alloc); dynarray(std::initializer_list<T> l) : dynarray_storage(elem_size * l.size()) , _ptr(static_cast<T *>(allocated_ptr())) , _size(l.size()) { assert(l.size() <= max_size()); std::uninitialized_copy(l.begin(), l.end(), begin()); }
bool String::grow(size_type new_size) { // check for too big if (max_size() <= new_size) CEGUI_THROW( std::length_error("Resulting CEGUI::String would be too big")); // increase, as we always null-terminate the buffer. ++new_size; if (new_size > d_reserve) { utf32* temp = CEGUI_NEW_ARRAY_PT(utf32, new_size, String); if (d_reserve > CEGUI_STR_QUICKBUFF_SIZE) { memcpy(temp, d_buffer, (d_cplength + 1) * sizeof(utf32)); CEGUI_DELETE_ARRAY_PT(d_buffer, utf32, d_reserve, String); } else { memcpy(temp, d_quickbuff, (d_cplength + 1) * sizeof(utf32)); } d_buffer = temp; d_reserve = new_size; return true; } return false; }
void reserve(size_type _Count) { // determine new minimum length of allocated storage if (max_size() < _Count) _Xlen(); // result too long else if (capacity() < _Count) { // not enough room, reallocate pointer _Ptr = this->_Alval.allocate(_Count); _TRY_BEGIN _Umove(this->_Myfirst, this->_Mylast, _Ptr); _CATCH_ALL this->_Alval.deallocate(_Ptr, _Count); _RERAISE; _CATCH_END size_type _Size = size(); if (this->_Myfirst != 0) { // destroy and deallocate old array _Destroy(this->_Myfirst, this->_Mylast); this->_Alval.deallocate(this->_Myfirst, this->_Myend - this->_Myfirst); } this->_Orphan_all(); this->_Myend = _Ptr + _Count; this->_Mylast = _Ptr + _Size; this->_Myfirst = _Ptr; } }
// 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; } }
void JFrame::push(jtype jt) { assert(m_top<(int)max_size()); if (jt < i32) { jt = i32; } switch (jt) { case i8: case i16: case u16: case i32: case jobj: m_stack[++m_top] = Val(jt); break; case i64: m_stack[++m_top] = Val(jt); m_stack[++m_top] = Val(jt); break; case flt32: m_stack[++m_top] = Val(jt); break; case dbl64: m_stack[++m_top] = Val(jt); m_stack[++m_top] = Val(jt); break; default: assert( jt == jretAddr ); m_stack[++m_top] = Val(jt); break; } }
MemoryUsage EdenMutableSpacePool::get_memory_usage() { size_t maxSize = (available_for_allocation() ? max_size() : 0); size_t used = used_in_bytes(); size_t committed = _space->capacity_in_bytes(); return MemoryUsage(initial_size(), used, committed, maxSize); }
bool String::grow(size_type new_size) { // check for too big if (max_size() <= new_size) std::length_error("Resulting CEGUI::String would be too big"); // increase, as we always null-terminate the buffer. ++new_size; if (new_size > d_reserve) { utf32* temp = new utf32[new_size]; if (d_reserve > STR_QUICKBUFF_SIZE) { memcpy(temp, d_buffer, (d_cplength + 1) * sizeof(utf32)); delete[] d_buffer; } else { memcpy(temp, d_quickbuff, (d_cplength + 1) * sizeof(utf32)); } d_buffer = temp; d_reserve = new_size; return true; } return false; }
// Compute desired plab size and latch result for later // use. This should be called once at the end of parallel // scavenge; it clears the sensor accumulators. void PLABStats::adjust_desired_plab_sz() { assert(ResizePLAB, "Not set"); if (_allocated == 0) { assert(_unused == 0, "Inconsistency in PLAB stats"); _allocated = 1; } double wasted_frac = (double)_unused/(double)_allocated; size_t target_refills = (size_t)((wasted_frac*TargetSurvivorRatio)/ TargetPLABWastePct); if (target_refills == 0) { target_refills = 1; } _used = _allocated - _wasted - _unused; size_t plab_sz = _used/(target_refills*ParallelGCThreads); if (PrintPLAB) gclog_or_tty->print(" (plab_sz = %d ", plab_sz); // Take historical weighted average _filter.sample(plab_sz); // Clip from above and below, and align to object boundary plab_sz = MAX2(min_size(), (size_t)_filter.average()); plab_sz = MIN2(max_size(), plab_sz); plab_sz = align_object_size(plab_sz); // Latch the result if (PrintPLAB) gclog_or_tty->print(" desired_plab_sz = %d) ", plab_sz); if (ResizePLAB) { _desired_plab_sz = plab_sz; } // Now clear the accumulators for next round: // note this needs to be fixed in the case where we // are retaining across scavenges. FIX ME !!! XXX _allocated = 0; _wasted = 0; _unused = 0; }
inline void IndexedList::erase(size_t const&e) { // check(); if (contains(e)) { // TRACE("remove "<<e<<" " <<_element[e]<<std::endl); // for (IntVector::const_iterator i(_list.begin()); i != _list.end(); ++i) // std::cout << *i << std::endl; /// on switch avec le dernier puis on réduit // std::cout << "_list[" << _element[e] << "] = " << _list.back() // << std::endl; _list[_element[e]] = front(); _element[front()] = _element[e]; // std::cout << "_element[" << e << "] = " << max_size() << std::endl; _element[e] = max_size(); _list[size() - 1] = -1; // std::cout << "_list[" << size() - 1 << "] = -1;" << std::endl; _list.erase(_list.begin() + _list.size() - 1); // std::cout << "###########" << std::endl; // for (IntVector::const_iterator i(_list.begin()); i != _list.end(); ++i) // std::cout << *i << std::endl; /// } // check(); // TRACE_N(size()); // TRACE_N(max_size()); // DEBUG_ASSERT("NO REALLOCATION ALLOWED"&&size()<=max_size()); }
void Acknowledge::send (Message_ptr m) { if (Data const* data = static_cast<Data const*> (m->find (Data::id))) { size_t max_payload_size ( params_.max_packet_size () - max_service_size); if (max_payload_size > data->size ()) { u32 max_size (max_payload_size - data->size ()); u32 max_elem (NRTM::max_count (max_size)); if (max_elem > 0) { Lock l (mutex_); Profile_ptr nrtm (create_nrtm (max_elem)); if (nrtm.get ()) m->add (nrtm); } } nrtm_timer_ = params_.nrtm_timeout (); // Reset timer. } out_->send (m); }
QWidget *ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { ItemWidget *w = m_cache[index.row()]; QWidget *editor = ( w != NULL) ? w->createEditor(parent) : new QPlainTextEdit(parent); if (editor == NULL) return NULL; editor->setPalette(m_editorPalette); editor->setFont(m_editorFont); editor->setObjectName("editor"); // maximal editor size QRect w_rect = parent->contentsRect(); QRect o_rect = option.rect; QSize max_size( w_rect.width() - o_rect.left() - 4, w_rect.height() - o_rect.top() - 4 ); editor->setMaximumSize(max_size); editor->setMinimumSize(max_size); connect( editor, SIGNAL(destroyed()), this, SLOT(editingStops()) ); connect( editor, SIGNAL(textChanged()), this, SLOT(editingStarts()) ); return editor; }
MemoryUsage CodeHeapPool::get_memory_usage() { size_t used = used_in_bytes(); size_t committed = _codeHeap->capacity(); size_t maxSize = (available_for_allocation() ? max_size() : 0); return MemoryUsage(initial_size(), used, committed, maxSize); }
MemoryUsage SurvivorContiguousSpacePool::get_memory_usage() { size_t maxSize = (available_for_allocation() ? max_size() : 0); size_t used = used_in_bytes(); size_t committed = committed_in_bytes(); return MemoryUsage(initial_size(), used, committed, maxSize); }
//template< typename Alloc > // dynarray(size_type c, const Alloc& alloc); dynarray(size_type c, const T& v) : dynarray_storage(elem_size * c) , _ptr(static_cast<T *>(allocated_ptr())) , _size(c) { assert(c <= max_size()); std::uninitialized_fill(_ptr, _ptr + c, v); }
const T* read_ptr(int16_t* count) { const T* result = nullptr; int16_t clamped_count = std::min<int16_t>(*count, size()); if (0 < clamped_count) { int16_t readIndex = read_index(0); assert(0 <= readIndex); assert(readIndex < max_size()); result = &(mBuffer[readIndex]); clamped_count = std::min<int16_t>(clamped_count, max_size() - readIndex); mSize -= clamped_count; assert(0 <= mSize); } *count = clamped_count; return result; }
static storage_type mask(T const k1, U const k2) { auto const i_k1 = integer_value_type(k1); auto const i_k2 = integer_value_type(k2); assert(i_k2 <= max_size() || i_k2 == end_index); assert(i_k1 <= i_k2); integer_value_type const span = i_k2 - i_k1; return bitops::ones<storage_type>(span) << i_k1; }
inline void IndexedList::check() const { for (size_t e(0); e < max_size(); ++e) { std::cout << e << " = " << _element[e] << std::endl; if (contains(e)) { assert(_list[_element[e]] == e); } } }
void wstring::resize(size_t n, wchar_t c) { if (n > max_size()) throw length_error("n > max_size()"); if (n > length()) append(n - length(), c); else erase(n); }
MemoryUsage G1OldGenPool::get_memory_usage() { size_t initial_sz = initial_size(); size_t max_sz = max_size(); size_t used = used_in_bytes(); size_t committed = _g1mm->old_space_committed(); return MemoryUsage(initial_sz, used, committed, max_sz); }