// private void EnsureCapacity(int byteCount) [instance] :1355 void MemoryStream::EnsureCapacity(int byteCount) { if ((Position() + (int64_t)byteCount) <= (int64_t)Capacity()) return; else if ((Position() + (int64_t)byteCount) <= (int64_t)(Capacity() + _nextIncrease)) ResizeTo(Capacity() + _nextIncrease); else ResizeTo((int)Position() + byteCount); }
/// <summary>オーバーフローを解決する</summary> void Resolve() { if (Count() < Capacity()) { return; } for (Size i = 0; i < Count() - Capacity(); ++i) { m_buffer.pop_front(); } }
Capacity Exword::GetCapacity() { exword_capacity_t cap = {0,}; int rsp; if (IsConnected()) { exword_setpath(m_device, (uint8_t*)GetStoragePath().utf8_str().data(), 0); rsp = exword_get_capacity(m_device, &cap); if (rsp != EXWORD_SUCCESS) return Capacity(); } return Capacity(cap.total, cap.free); }
template<typename... U> void PushHead(U&&... u) { condcheck(Capacity() != 0); if(Empty()){ m_Head = 0; m_CircleQ[0] = T(std::forward<U>(u)...); m_CurrSize = 1; }else{ m_Head = ((m_Head + Capacity() - 1) % Capacity()); m_CircleQ[m_Head] = T(std::forward<U>(u)...); m_CurrSize = std::min<size_t>(m_CurrSize + 1, Capacity()); } }
void NxDeviceOscOutputMessage::CheckForAvailableBundleSpace() { unsigned long required = Size() + ((ElementSizeSlotRequired())?4:0) + 16; if( required > Capacity() ) throw OutOfBufferMemoryException(); }
void OutboundPacketStream::CheckForAvailableBundleSpace() { unsigned long required = Size() + ((ElementSizeSlotRequired())?4:0) + 16; if( required > Capacity() ) throw OutOfBufferMemoryException(); }
void PopHead() { if(!Empty()){ m_Head = (m_Head + 1) % Capacity(); m_CurrSize--; } }
template <class T> void Vector<T>::AutoAllocate() { if(_origin == NULL) Allocate(2U); else if(_last == _end) Allocate(Capacity() << 1U); }
/** free the blob's memory */ inline void Free() { if (Capacity() > 0) { RawFree(&Hdr()); InitEmpty(); } }
void VectorBase::Reserve( SizeType capacity, SizeType elementSize ) { SizeType oldCapacity = Capacity(); SizeType oldCount = Count(); if( capacity > oldCapacity ) { const SizeType wholeAllocation = sizeof(SizeType) * 2 + capacity * elementSize; void* wholeData = (void*)malloc( wholeAllocation ); #if defined( DEBUG_ENABLED ) // in debug build this will help identify a vector of uninitialized data memset( wholeData, 0xaa, wholeAllocation ); #endif SizeType* metaData = reinterpret_cast< SizeType* >( wholeData ); *metaData++ = capacity; *metaData++ = oldCount; if( mData ) { // copy over the old data memcpy( metaData, mData, oldCount * elementSize ); // release old buffer Release(); } mData = metaData; } }
String::String(const uint id) { if (HINSTANCE const hInstance = Application::Instance::GetLanguage().GetResourceHandle()) { uint length; do { Reserve( Capacity() + BLOCK_SIZE ); length = ::LoadString( hInstance, id, Ptr(), Capacity() + 1 ); } while (length == Capacity()); ShrinkTo( length ); } }
// private void ResizeTo(int newSize) [instance] :1371 void MemoryStream::ResizeTo(int newSize) { uArray* newBuffer = uArray::New(::TYPES[0/*byte[]*/], newSize); ::g::Uno::Array::Copy1(::TYPES[6/*Uno.Array.Copy<byte>*/], _buffer, newBuffer, uPtr(_buffer)->Length()); _buffer = newBuffer; _nextIncrease = Capacity(); }
DZRawData __fastcall DZRawData::operator-(WORD tag) { DZRawData res(Capacity()); if (imp) { const unsigned char *p = begin(); const unsigned char *e = end(); XWord tg, sz; while (p + 3 < e) { tg.b[0] = *p++; tg.b[1] = *p++; sz.b[0] = *p++; sz.b[1] = *p++; if (tg.w != tag) { res += tg.w; res += sz.w; while (p < e && sz.w-- > 0) res += *p++; } else p += sz.w; } while (p < e) res += *p++; } return res; }
inline size_t Compact(size_t leastLength) { uint32_t writableBytes = WriteableBytes(); if (writableBytes < leastLength) { return 0; } uint32_t readableBytes = ReadableBytes(); uint32_t total = Capacity(); char* newSpace = NULL; if (readableBytes > 0) { newSpace = (char*) malloc(readableBytes); if (NULL == newSpace) { return 0; } memcpy(newSpace, m_buffer + m_read_idx, readableBytes); } if (NULL != m_buffer) { free(m_buffer); } m_read_idx = 0; m_write_idx = readableBytes; m_buffer_len = readableBytes; m_buffer = newSpace; return total - readableBytes; }
/** free the blob's memory */ FORCEINLINE void Free() { if (Capacity() > 0) { RawFree(&Hdr()); InitEmpty(); } }
int NDOStreamMsg::WriteBin(void *data, size_t size) { if (_end <= _op_addr || size >= Capacity()){ return -1; } if (size ==0){ if (-1 == _writeMarker(ENDSTREAM_MARKER_BIN, 0)) { return -1; } return 0; } else { if (-1 == _writeMarker(ENDSTREAM_MARKER_BIN, 1)) { return -1; } } size_t free_size = _end - _op_addr; if (size + 2 <= free_size) { _WriteOrg((NDUINT16)size); if (size > 0) memcpy(_op_addr, data, size); MsgLength() += (NDUINT16)size; _op_addr += size; return 0; } return -1; }
void OutboundPacketStream::CheckForAvailableMessageSpace( const char *addressPattern ) { // plus 4 for at least four bytes of type tag unsigned long required = Size() + ((ElementSizeSlotRequired()) ? 4 : 0) + RoundUp4(static_cast<unsigned long>(strlen(addressPattern)) + 1) + 4; if( required > Capacity() ) throw OutOfBufferMemoryException(); }
//============================================================ void TNetMessageBuffer::Update(){ TInt capacity = Capacity(); TNetSerial messageSerial = _messageHead.Serial(); TNetTick messageTick = _messageHead.Tick(); TNetHash hash = CalculateHash(messageSerial, messageTick, _pData, _dataLength); _netHead.SetLength((TNetLength)capacity); _netHead.SetHash(hash); }
Errors OutboundPacketStream::CheckForAvailableMessageSpace( const char *addressPattern ) { // plus 4 for at least four bytes of type tag std::size_t required = Size() + ((ElementSizeSlotRequired())?4:0) + RoundUp4(std::strlen(addressPattern) + 1) + 4; return (required > Capacity()) ? OUT_OF_BUFFER_MEMORY_ERROR : SUCCESS; }
void OutboundPacketStream::CheckForAvailableArgumentSpace( long argumentLength ) { // plus three for extra type tag, comma and null terminator unsigned long required = static_cast<unsigned long>((argumentCurrent_ - data_) + argumentLength + RoundUp4( (end_ - typeTagsCurrent_) + 3 )); if( required > Capacity() ) throw OutOfBufferMemoryException(); }
/// <summary>値で埋める</summary> /// <param name="isPost">末尾に追加するかどうか</param> void Fill(bool isPost) { Size loop = Capacity() - Count(); for (Size i = 0; i < loop; ++i) { Save(Type(), isPost); } }
Errors OutboundPacketStream::CheckForAvailableArgumentSpace( std::size_t argumentLength ) { // plus three for extra type tag, comma and null terminator std::size_t required = (argumentCurrent_ - data_) + argumentLength + RoundUp4( (end_ - typeTagsCurrent_) + 3 ); return (required > Capacity()) ? OUT_OF_BUFFER_MEMORY_ERROR : SUCCESS; }
void NxDeviceOscOutputMessage::CheckForAvailableArgumentSpace( long argumentLength ) { // plus three for extra type tag, comma and null terminator unsigned long required = (argumentCurrent_ - data_) + argumentLength + RoundUp4( (end_ - typeTagsCurrent_) + 3 ); if( required > Capacity() ) throw OutOfBufferMemoryException(); }
bool ResizeFileSystemJob::run(Report& parent) { Q_ASSERT(partition().fileSystem().firstSector() != -1); Q_ASSERT(partition().fileSystem().lastSector() != -1); Q_ASSERT(newLength() <= partition().length()); if (partition().fileSystem().firstSector() == -1 || partition().fileSystem().lastSector() == -1 || newLength() > partition().length()) { kWarning() << "file system first sector: " << partition().fileSystem().firstSector() << ", last sector: " << partition().fileSystem().lastSector() << ", new length: " << newLength() << ", partition length: " << partition().length(); return false; } bool rval = false; Report* report = jobStarted(parent); if (partition().fileSystem().length() == newLength()) { report->line() << i18ncp("@info/plain", "The file system on partition <filename>%2</filename> already has the requested length of 1 sector.", "The file system on partition <filename>%2</filename> already has the requested length of %1 sectors.", newLength(), partition().deviceNode()); rval = true; } else { report->line() << i18nc("@info/plain", "Resizing file system from %1 to %2 sectors.", partition().fileSystem().length(), newLength()); FileSystem::CommandSupportType support = (newLength() < partition().fileSystem().length()) ? partition().fileSystem().supportShrink() : partition().fileSystem().supportGrow(); switch(support) { case FileSystem::cmdSupportBackend: { Report* childReport = report->newChild(); childReport->line() << i18nc("@info/plain", "Resizing a %1 file system using internal backend functions.", partition().fileSystem().name()); rval = resizeFileSystemBackend(*childReport); break; } case FileSystem::cmdSupportFileSystem: { const qint64 newLengthInByte = Capacity(newLength() * device().logicalSectorSize()).toInt(Capacity::Byte); rval = partition().fileSystem().resize(*report, partition().deviceNode(), newLengthInByte); break; } default: report->line() << i18nc("@info/plain", "The file system on partition <filename>%1</filename> cannot be resized because there is no support for it.", partition().deviceNode()); break; } if (rval) partition().fileSystem().setLastSector(partition().fileSystem().firstSector() + newLength() - 1); } jobFinished(*report, rval); return rval; }
void NxDeviceOscOutputMessage::CheckForAvailableMessageSpace( const char *addressPattern ) { // plus 4 for at least four bytes of type tag unsigned long required = Size() + ((ElementSizeSlotRequired())?4:0) + RoundUp4(strlen(addressPattern) + 1) + 4; if( required > Capacity() ) throw OutOfBufferMemoryException(); }
void OutboundPacketStream::CheckForAvailableArgumentSpace( std::size_t argumentLength ) { // plus three for extra type tag, comma and null terminator std::size_t required = (argumentCurrent_ - data_) + argumentLength + RoundUp4( (end_ - typeTagsCurrent_) + 3 ); if( required > Capacity() ) throw OutOfBufferMemoryException(); }
/** fixing the four bytes at the end of blob data - useful when blob is used to hold string */ FORCEINLINE void FixTail() const { if (Capacity() > 0) { byte *p = &data[Length()]; for (uint i = 0; i < tail_reserve; i++) { p[i] = 0; } } }
inline bool EnsureWritableBytes(size_t minWritableBytes, bool growzero = false) { if (WriteableBytes() >= minWritableBytes) { return true; } else { size_t newCapacity = Capacity(); if (0 == newCapacity) { newCapacity = DEFAULT_BUFFER_SIZE; } size_t minNewCapacity = GetWriteIndex() + minWritableBytes; while (newCapacity < minNewCapacity) { newCapacity <<= 1; } char* tmp = NULL; //tmp = (char*) realloc(m_buffer, newCapacity); tmp = (char*) malloc(newCapacity); if (NULL != tmp) { if (growzero) { memset(tmp, 0, newCapacity); } if (NULL != m_buffer) { memcpy(tmp, m_buffer, Capacity()); } if (NULL != m_buffer) { free(m_buffer); } m_buffer = tmp; m_buffer_len = newCapacity; return true; } return false; } }
int Buffer::Size(int sz) { m_size = sz; if(sz > 0) { Capacity(sz); } return m_size; }
/** reallocate blob data if needed */ void SmartAlloc(size_t new_size) { if (Capacity() >= new_size) return; /* calculate minimum block size we need to allocate * and ask allocation policy for some reasonable block size */ new_size = AllocPolicy(header_size + new_size + tail_reserve); /* allocate new block and setup header */ BlobHeader *tmp = RawAlloc(new_size); tmp->items = Length(); tmp->capacity = new_size - (header_size + tail_reserve); /* copy existing data */ if (tmp->items != 0) memcpy(tmp + 1, data, tmp->items); /* replace our block with new one */ if (Capacity() > 0) RawFree(&Hdr()); Init(tmp); }