Beispiel #1
0
char* palAtomMemoryManager::CopyString(const char* str) {
  uint32_t length = palStringLength(str) + 1;

  if (length >= PAL_ATOM_PAGE_SIZE) {
    // very large string, won't fit in page
    total_large_strings++;
    total_allocated_memory += length;
    return palStringDuplicate(str);
  }
  const uint32_t page_size = ((palPageAllocator*)g_PageAllocator)->GetPageSize();
  if (page == NULL) {
    // initial run
    page = (char*)g_PageAllocator->Allocate(PAL_ATOM_PAGE_SIZE, page_size);
    offset = 0;
    total_allocated_memory += PAL_ATOM_PAGE_SIZE;
  }
  if (offset + length >= PAL_ATOM_PAGE_SIZE) {
    total_wasted_memory += (PAL_ATOM_PAGE_SIZE - offset);
    total_allocated_memory += PAL_ATOM_PAGE_SIZE;
    page = (char*)g_PageAllocator->Allocate(PAL_ATOM_PAGE_SIZE, page_size);
    offset = 0;
  }
  char* copy = page+offset;
  palMemoryCopyBytes(page+offset, str, length);
  offset += length;
  return copy;
}
bool palBinaryReader::Read(size_t length, void* r) {
	if (buffer_p_ + length >= buffer_end_) {
		// EOF
		return false;
	}
	palMemoryCopyBytes(r, buffer_p_, length);
	buffer_p_ += length;
	return true;
}