本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}