예제 #1
0
// 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);
}
예제 #2
0
파일: Memento.hpp 프로젝트: rumiaqua/DxGame
	/// <summary>オーバーフローを解決する</summary>
	void Resolve()
	{
		if (Count() < Capacity())
		{
			return;
		}
		for (Size i = 0; i < Count() - Capacity(); ++i)
		{
			m_buffer.pop_front();
		}
	}
예제 #3
0
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);
}
예제 #4
0
파일: cachequeue.hpp 프로젝트: etorth/mir2x
 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();
}
예제 #7
0
파일: cachequeue.hpp 프로젝트: etorth/mir2x
 void PopHead()
 {
     if(!Empty()){
         m_Head = (m_Head + 1) % Capacity();
         m_CurrSize--;
     }
 }
예제 #8
0
파일: Vector.cpp 프로젝트: Karkasos/Core
template <class T> void Vector<T>::AutoAllocate()
{
	if(_origin == NULL)
		Allocate(2U);
	else if(_last == _end)
		Allocate(Capacity() << 1U);
}
예제 #9
0
 /** free the blob's memory */
 inline void Free()
 {
     if (Capacity() > 0) {
         RawFree(&Hdr());
         InitEmpty();
     }
 }
예제 #10
0
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;
  }
}
예제 #11
0
		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 );
			}
		}
예제 #12
0
// 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();
}
예제 #13
0
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;
}
예제 #14
0
파일: buffer.hpp 프로젝트: dawnbreaks/arch
				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;
				}
예제 #15
0
	/** free the blob's memory */
	FORCEINLINE void Free()
	{
		if (Capacity() > 0) {
			RawFree(&Hdr());
			InitEmpty();
		}
	}
예제 #16
0
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;
}
예제 #17
0
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();
}
예제 #18
0
//============================================================
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);
}
예제 #19
0
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;
}
예제 #20
0
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();
}
예제 #21
0
파일: Memento.hpp 프로젝트: rumiaqua/DxGame
	/// <summary>値で埋める</summary>
	/// <param name="isPost">末尾に追加するかどうか</param>
	void Fill(bool isPost)
	{
		Size loop = Capacity() - Count();
		for (Size i = 0; i < loop; ++i)
		{
			Save(Type(), isPost);
		}
	}
예제 #22
0
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();
	}
예제 #26
0
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();
}
예제 #27
0
	/** 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;
			}
		}
	}
예제 #28
0
파일: buffer.hpp 프로젝트: dawnbreaks/arch
				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;
					}
				}
예제 #29
0
	int Buffer::Size(int sz)
	{
		m_size = sz;

		if(sz > 0)
		{
			Capacity(sz);
		}

		return m_size;
	}
예제 #30
0
파일: blob.hpp 프로젝트: jemmyw/openttd
	/** 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);
	}