int MemoryInputStream::Read(void* p, int len) { int avail = (int)(_end - _ptr); if (len > avail) len = avail; XlCopyMemory(p, _ptr, len); _ptr += len; return len; }
SharedPkt MakeSharedPkt(const void* begin, const void* end) { auto& heap = SharedPkt::GetHeap(); auto size = size_t(ptrdiff_t(end) - ptrdiff_t(begin)); SharedPkt pkt(heap.Allocate((unsigned)size), size); if (pkt.begin()) { XlCopyMemory(pkt.begin(), begin, size); } return std::move(pkt); }
void DirectorySearchRules::ResolveFile(ResChar destination[], unsigned destinationCount, const ResChar baseName[]) const { ResChar tempBuffer[MaxPath]; auto splitter = MakeFileNameSplitter(baseName); bool baseFileExist = false; if (!splitter.ParametersWithDivider().Empty()) { XlCopyString(tempBuffer, splitter.AllExceptParameters()); baseFileExist = DoesFileExist(tempBuffer); } else { baseFileExist = DoesFileExist(baseName); } // by definition, we always check the unmodified file name first if (!baseFileExist) { const ResChar* b = _buffer; if (!_bufferOverflow.empty()) { b = AsPointer(_bufferOverflow.begin()); } // We want to support the case were destination == baseName // But that cases requires another temporary buffer, because we // don't want to trash "baseName" while searching for matches ResChar* workingBuffer = (baseName!=destination) ? destination : tempBuffer; unsigned workingBufferSize = (baseName!=destination) ? destinationCount : unsigned(dimof(tempBuffer)); for (unsigned c=0; c<_startPointCount; ++c) { XlConcatPath(workingBuffer, workingBufferSize, &b[_startOffsets[c]], splitter.AllExceptParameters().begin(), splitter.AllExceptParameters().end()); if (DoesFileExist(workingBuffer)) { SplitPath<ResChar>(workingBuffer).Simplify().Rebuild(workingBuffer, workingBufferSize); if (workingBuffer != destination) { auto workingBufferLen = std::min((ptrdiff_t)XlStringLen(workingBuffer), ptrdiff_t(destinationCount) - 1); auto colonLen = (ptrdiff_t)splitter.ParametersWithDivider().Length(); auto colonCopy = std::min(ptrdiff_t(destinationCount) - workingBufferLen - 1, colonLen); assert((workingBufferLen + colonCopy) < ptrdiff_t(destinationCount)); if (colonCopy > 0) XlMoveMemory(&destination[workingBufferLen], splitter.ParametersWithDivider().begin(), colonCopy); destination[workingBufferLen + colonCopy] = '\0'; assert(workingBufferLen < (ptrdiff_t(destinationCount)-1)); XlCopyMemory(destination, workingBuffer, workingBufferLen); } else { XlCatString(destination, destinationCount, splitter.ParametersWithDivider()); } return; } } } if (baseName != destination) XlCopyString(destination, destinationCount, baseName); SplitPath<ResChar>(destination).Simplify().Rebuild(destination, destinationCount); }
void ConstantBuffer::Update(DeviceContext& context, const void* data, size_t byteCount) { // context.GetUnderlying()->UpdateSubresource( // _underlying, 0, nullptr, data, byteCount, byteCount); D3D11_MAPPED_SUBRESOURCE result; ID3D::DeviceContext* devContext = context.GetUnderlying(); HRESULT hresult = devContext->Map(_underlying.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &result); if (SUCCEEDED(hresult) && result.pData) { XlCopyMemory(result.pData, data, byteCount); devContext->Unmap(_underlying.get(), 0); } }
void DirectorySearchRules::AddSearchDirectory(StringSection<ResChar> dir) { // Attempt to fit this directory into our buffer. // note that we have limited space in the buffer, but we can't really // rely on all directory names remaining small and convenient... If we // overflow our fixed size buffer, we can use the dynamically // allocated "_bufferOverflow" assert((_startPointCount+1) <= dimof(_startOffsets)); if ((_startPointCount+1) > dimof(_startOffsets)) { // limited number of directories that can be pushed into a single "search rules" // this allows us to avoid a little bit of awkward dynamic memory allocation return; } // Check for duplicates // Duplicates are bad because they will increase the number of search operations if (HasDirectory(dir)) return; unsigned allocationLength = (unsigned)(dir.Length() + 1); if (_bufferOverflow.empty() && (_bufferUsed + allocationLength <= dimof(_buffer))) { // just append this new string to our buffer, and add a new start offset XlCopyMemory(&_buffer[_bufferUsed], dir.begin(), (allocationLength-1) * sizeof(ResChar)); _buffer[_bufferUsed+allocationLength-1] = '\0'; } else { if (_bufferOverflow.empty()) { _bufferOverflow.resize(_bufferUsed + allocationLength); XlCopyMemory(AsPointer(_bufferOverflow.begin()), _buffer, _bufferUsed * sizeof(ResChar)); XlCopyMemory(PtrAdd(AsPointer(_bufferOverflow.begin()), _bufferUsed * sizeof(ResChar)), dir.begin(), (allocationLength-1) * sizeof(ResChar)); _bufferOverflow[_bufferUsed+allocationLength-1] = '\0'; } else { assert(_bufferOverflow.size() == allocationLength); auto i = _bufferOverflow.insert(_bufferOverflow.end(), dir.begin(), dir.end()); _bufferOverflow.insert(i + dir.Length(), 0); } } _startOffsets[_startPointCount++] = _bufferUsed; _bufferUsed += allocationLength; }