本文整理汇总了C++中DataChunk::GetByteSize方法的典型用法代码示例。如果您正苦于以下问题:C++ DataChunk::GetByteSize方法的具体用法?C++ DataChunk::GetByteSize怎么用?C++ DataChunk::GetByteSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataChunk
的用法示例。
在下文中一共展示了DataChunk::GetByteSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Allocate
void DataContainer::Allocate() {
// Check that memory has not been allocated
if (m_pAllocatedMemory != NULL) {
_EXCEPTIONT("Attempting Allocate() on attached DataContainer");
}
// Allocate memory as one contiguous chunk
size_t sTotalByteSize = GetTotalByteSize();
m_pAllocatedMemory =
reinterpret_cast<unsigned char*>(malloc(sTotalByteSize));
if (m_pAllocatedMemory == NULL) {
_EXCEPTIONT("Out of memory");
}
// Initialize allocated memory to zero
memset(m_pAllocatedMemory, 0, sTotalByteSize);
// Assign memory to DataChunks
unsigned char * pAccumulated = m_pAllocatedMemory;
for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
DataChunk * pDataChunk =
reinterpret_cast<DataChunk*>(m_vecDataChunks[i]);
pDataChunk->AttachToData(
reinterpret_cast<void *>(pAccumulated));
#pragma message "Alignment may be an issue here on 32-bit systems"
pAccumulated += pDataChunk->GetByteSize();
}
}
示例2: GetTotalByteSize
size_t DataContainer::GetTotalByteSize() const {
// Get the accumulated size of all DataChunks
size_t sAccumulated = 0;
for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
DataChunk * pDataChunk =
reinterpret_cast<DataChunk*>(m_vecDataChunks[i]);
// Verify byte alignment
size_t sByteSize = pDataChunk->GetByteSize();
if (sByteSize % sizeof(size_t) != 0) {
_EXCEPTIONT("Misaligned array detected in DataContainer");
}
sAccumulated += sByteSize;
}
return sAccumulated;
}
示例3: AttachTo
void DataContainer::AttachTo(
unsigned char * pAllocatedMemory
) {
if (m_pAllocatedMemory != NULL) {
_EXCEPTIONT("Attempting AttachTo() on attached DataContainer");
}
m_fOwnsData = false;
m_pAllocatedMemory = pAllocatedMemory;
// Assign memory to DataChunks
unsigned char * pAccumulated = m_pAllocatedMemory;
for (size_t i = 0; i < m_vecDataChunks.size(); i++) {
DataChunk * pDataChunk =
reinterpret_cast<DataChunk *>(m_vecDataChunks[i]);
pDataChunk->AttachToData(
reinterpret_cast<void *>(pAccumulated));
pAccumulated += pDataChunk->GetByteSize();
}
}