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();
	}
}
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;
}
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();
	}
}