当前位置: 首页>>代码示例>>C++>>正文


C++ DataPtr::allocate方法代码示例

本文整理汇总了C++中DataPtr::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ DataPtr::allocate方法的具体用法?C++ DataPtr::allocate怎么用?C++ DataPtr::allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataPtr的用法示例。


在下文中一共展示了DataPtr::allocate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildTexture

Serializable* ExporterBackend::buildTexture(CSLImage* image, CSIBCPixMap& pixMap)
{
	uint depth = pixMap.GetTotalPixelDepthByte();

	// We only handly 32 bit and 24bit textures right now

	if (depth != 4 && depth != 3)
	{
		ZENIC_WARNING("Unsupported pixeldepth (" << pixMap.GetTotalPixelDepthByte() << ") for texture " << image->GetSourceFile() <<
					 "skipping");
		return 0;
	}

	Texture* texture = zenic_new Texture;
	TextureData* textureData = zenic_new TextureData;

	textureData->setWidth(u16(pixMap.GetWidth()));
	textureData->setHeight(u16(pixMap.GetHeight()));
	textureData->setFlags(TextureData::RGB);

	DataPtr<u8> imageData;

	uint imageSize = pixMap.GetWidth() * pixMap.GetHeight() * depth;

	imageData.allocate(imageSize);
	memcpy(imageData.objects(), pixMap.GetMap(), imageSize);

	textureData->setImageData(imageData);
	texture->setData(textureData);

	return texture;
}
开发者ID:,项目名称:,代码行数:32,代码来源:

示例2: encodeTypedElements

 inline void encodeTypedElements( BinaryPortable *, T *, DataPtr &data, T *t, int nCount)
 {
     UInt32 nBufferSize = sizeof(T) * nCount;
     UInt32 nAlloc = data.allocate(nBufferSize);
     RCF_ASSERT(nAlloc == nBufferSize);
     T *buffer = reinterpret_cast<T *>(data.get());
     memcpy(buffer, t, nBufferSize);
     RCF::machineToNetworkOrder(buffer, sizeof(T), nCount);
 }
开发者ID:r0ssar00,项目名称:iTunesSpeechBridge,代码行数:9,代码来源:Encoding.hpp

示例3: write

int FifoStream::write(const void* buffer, int size)
{
	int maxWrite = 0;
	if (m_writing <= m_reading)
		maxWrite = (m_reading-m_writing)-1;
	else
		maxWrite = ((m_reading+m_buffer.count())-m_writing)-1;

	if (maxWrite < size)
	{
		DataPtr<u8> newData;

		// TODO: resize 2^x to allow for efficient performance

		newData.allocate(m_buffer.count() + (size-maxWrite));

		if (m_reading <= m_writing)
		{
			::memcpy(newData.objects(), &m_buffer.objects()[m_reading], m_writing-m_reading);
			m_writing -= m_reading;
			m_reading = 0;
		}
		else
		{
			// INCORRECT!
			::memcpy(newData.objects(), m_buffer.objects() + m_reading, m_buffer.count()-m_reading);
			::memcpy(newData.objects() + (m_buffer.count()-m_reading), m_buffer.objects(), m_writing);
			m_writing = m_reading-m_writing;
			m_reading = 0;
		}

		m_buffer.free();
		m_buffer = newData;
	}

	int actualWrite = size;
	const char* currentBuffer = static_cast<const char*>(buffer);
	while (size > 0)
	{
		int currentWrite = size;
		if (uint(m_writing + currentWrite) > m_buffer.count())
			currentWrite = m_buffer.count() - m_writing;

		::memcpy(m_buffer.objects() + m_writing, currentBuffer, currentWrite);

		m_writing += currentWrite;
		if (m_buffer.count() == uint(m_writing))
			m_writing = 0;

		currentBuffer += currentWrite;
		size -= currentWrite;
	}

	return actualWrite;
}
开发者ID:jsvennevid,项目名称:tbl-4edges,代码行数:55,代码来源:FifoStream.cpp

示例4: EncodingBinaryPortable_toDataImpl

 void EncodingBinaryPortable_toDataImpl(
     DataPtr &       data, 
     T *             t, 
     int             nCount)
 {
     UInt32 nBufferSize = sizeof(T) * nCount;
     UInt32 nAlloc = data.allocate(nBufferSize);
     RCF_ASSERT_EQ(nAlloc , nBufferSize);
     RCF_UNUSED_VARIABLE(nAlloc);
     T *buffer = reinterpret_cast<T *>(data.get());
     memcpy(buffer, t, nBufferSize);
     RCF::machineToNetworkOrder(buffer, sizeof(T), nCount);
 }
开发者ID:MorelM35,项目名称:ESIR_MorKaneGame,代码行数:13,代码来源:I_Stream.cpp

示例5: get

 bool IStream::get(DataPtr &value)
 {
     Byte8 byte;
     read_byte( byte );
     if (byte == Data)
     {
         UInt32 length = 0;
         read_int(length);
         value.allocate(length);
         read(value.get(), length);
         return true;
     }
     else
     {
         putback_byte(byte);
         return false;
     }
 }
开发者ID:MorelM35,项目名称:ESIR_MorKaneGame,代码行数:18,代码来源:Stream.cpp


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