void moQuaternion<Real>::DecomposeTwistTimesSwing ( const moVector3<Real>& rkV1, moQuaternion& rkTwist, moQuaternion& rkSwing) { moVector3<Real> kV2 = Rotate(rkV1); rkSwing = Align(rkV1,kV2); rkTwist = (*this)*rkSwing.Conjugate(); }
void moQuaternion<Real>::DecomposeSwingTimesTwist ( const moVector3<Real>& rkV1, moQuaternion& rkSwing, moQuaternion& rkTwist) { moVector3<Real> kV2 = Rotate(rkV1); rkSwing = Align(rkV1,kV2); rkTwist = rkSwing.Conjugate()*(*this); }
void PadByteStream(TArray<uint8>& CompressedByteStream, const int32 Alignment, uint8 sentinel) { int32 Pad = Align( CompressedByteStream.Num(), 4 ) - CompressedByteStream.Num(); for ( int32 i = 0 ; i < Pad ; ++i ) { CompressedByteStream.Add(sentinel); } }
void UTexAligner::Align( UWorld* InWorld, ETexAlign InTexAlignType ) { for( int32 LevelIndex = 0; LevelIndex < InWorld->GetNumLevels(); ++LevelIndex ) { ULevel* Level = InWorld->GetLevel(LevelIndex); Align( InWorld, InTexAlignType, Level->Model ); } }
void SeeDif::InsertDialog(Interactor* dialog) { World *world=GetWorld(); Coord x,y; Align(Center, 0, 0, x , y); world->InsertTransient(dialog, this, x, y, Center); }
DynamicConstantBuffer::DynamicConstantBuffer(UINT constantSize, UINT maxDrawsPerFrame, UINT frameCount) : m_alignedPerDrawConstantBufferSize(Align(constantSize)), // Constant buffers must be aligned for hardware requirements. m_maxDrawsPerFrame(maxDrawsPerFrame), m_frameCount(frameCount), m_constantBuffer(nullptr) { m_perFrameConstantBufferSize = m_alignedPerDrawConstantBufferSize * m_maxDrawsPerFrame; }
/** * Compact the list down to the smallest block size boundary. */ FORCEINLINE void Compact() { uint capacity = Align(this->items, S); if (capacity >= this->capacity) return; this->capacity = capacity; this->data = ReallocT(this->data, this->capacity); }
// As you can see, we can free a single block of memory at any time without being inside a GC void GCAllocator::Free(void * ptr, int size) { CROSSNET_ASSERT(IsAligned(ptr), ""); AllocStructure * freedPtr = static_cast<AllocStructure *>(ptr); int alignedSize = Align(size); InternalFree(freedPtr, alignedSize); }
namespace D3D12RHI { /** Sizes of constant buffers defined in ED3D11ShaderOffsetBuffer. */ const uint32 GConstantBufferSizes[MAX_CONSTANT_BUFFER_SLOTS] = { // CBs must be a multiple of 16 (uint32)Align(MAX_GLOBAL_CONSTANT_BUFFER_SIZE, 16), }; }
unsigned int s3c_mfc_get_data_buf_phys_addr() { unsigned int phys_addr; s3c_mfc_phys_data_buf = s3c_mfc_get_risc_buf_phys_addr(MFC_MAX_INSTANCE_NUM); phys_addr = Align(s3c_mfc_phys_data_buf, 4*BUF_L_UNIT); return phys_addr; }
void DefineGlobal(Symbol p) { Align(p); if (p->sclass != TK_STATIC) { Export(p); } Print("%s:\t", GetAccessName(p)); }
void Sted::InsertDialog (Interactor* dialog) { World* world = GetWorld(); Coord x, y; Align(Center, 0, 0, x, y); GetRelative(x, y, world); world->InsertTransient(dialog, this, x, y, Center); }
bool TextStyleData::readProperties(XmlReader& e) { const QStringRef& tag(e.name()); if (tag == "name") name = e.readElementText(); else if (tag == "family") family = e.readElementText(); else if (tag == "size") size = e.readDouble(); else if (tag == "bold") bold = e.readInt(); else if (tag == "italic") italic = e.readInt(); else if (tag == "underline") underline = e.readInt(); else if (tag == "align") setAlign(Align(e.readInt())); else if (tag == "anchor") // obsolete e.skipCurrentElement(); else if (ElementLayout::readProperties(e)) ; else if (tag == "sizeIsSpatiumDependent" || tag == "spatiumSizeDependent") sizeIsSpatiumDependent = e.readInt(); else if (tag == "frameWidth") { // obsolete hasFrame = true; frameWidthMM = e.readDouble(); } else if (tag == "frameWidthS") { hasFrame = true; frameWidth = Spatium(e.readDouble()); } else if (tag == "frame") hasFrame = e.readInt(); else if (tag == "square") _square = e.readInt(); else if (tag == "paddingWidth") // obsolete paddingWidthMM = e.readDouble(); else if (tag == "paddingWidthS") paddingWidth = Spatium(e.readDouble()); else if (tag == "frameRound") frameRound = e.readInt(); else if (tag == "frameColor") frameColor = e.readColor(); else if (tag == "foregroundColor") foregroundColor = e.readColor(); else if (tag == "backgroundColor") backgroundColor = e.readColor(); else if (tag == "circle") circle = e.readInt(); else if (tag == "systemFlag") systemFlag = e.readInt(); else return false; return true; }
void LibFiles::WriteFiles(FILE *stream, ObjInt align) { int i =0; for (FileIterator it = FileBegin(); it != FileEnd(); ++it) { Align(stream, align); (*it)->offset = ftell(stream); WriteData(stream, (*it)->data, (*it)->name); } }
void DefineFloatConstant(Symbol p) { int align = p->ty->align; p->aname = FormatName(".flt%d", FloatNum++); Align(p); Print("%s:\t", p->aname); DefineValue(p->ty, p->val); }
// This method will grow array's MaxCount. No items will be allocated. // The allocated memory is not initialized because items could be inserted // and removed at any time - so initialization should be performed in // upper level functions like Insert() void FArray::GrowArray(int count, int elementSize) { guard(FArray::GrowArray); assert(count > 0); int prevCount = MaxCount; // check for available space int newCount = DataCount + count; if (newCount > MaxCount) { // Not enough space, resize ... // Allow small initial size of array const int minCount = 4; if (newCount > minCount) { MaxCount = Align(DataCount + count, 16) + 16; } else { MaxCount = minCount; } // Align memory block to reduce fragmentation int dataSize = Align(MaxCount * elementSize, 16); // Recompute MaxCount in a case if alignment increases its capacity MaxCount = dataSize / elementSize; // Reallocate memory if (!IsStatic()) { DataPtr = appRealloc(DataPtr, dataSize); } else { // "static" array becomes non-static void* oldData = DataPtr; // this is a static pointer DataPtr = appMalloc(dataSize); memcpy(DataPtr, oldData, prevCount * elementSize); } } unguardf("%d x %d", count, elementSize); }
HRESULT DataTargetReader::SkipPointer() { HRESULT hr = S_OK; if (m_remotePointerSize == 0) { IfFailRet(GetRemotePointerSize(&m_remotePointerSize)); } _ASSERTE(m_remotePointerSize == 4 || m_remotePointerSize == 8); Align(m_remotePointerSize); return SkipBytes(m_remotePointerSize); }
NTSTATUS RdrSmb2EncodeTreeConnectRequest( PSMB_PACKET pPacket, PBYTE* ppCursor, PULONG pulRemaining, PCWSTR pwszPath ) { NTSTATUS status = STATUS_SUCCESS; PRDR_SMB2_TREE_CONNECT_REQUEST_HEADER pHeader = NULL; ULONG ulPathLength = LwRtlWC16StringNumChars(pwszPath); PBYTE pFilename = NULL; if (ulPathLength > 256) { status = STATUS_INVALID_PARAMETER; BAIL_ON_NT_STATUS(status); } pHeader = (PRDR_SMB2_TREE_CONNECT_REQUEST_HEADER) *ppCursor; /* Advance cursor past header to ensure buffer space */ status = Advance(ppCursor, pulRemaining, sizeof(*pHeader)); BAIL_ON_NT_STATUS(status); pHeader->usLength = SMB_HTOL16(sizeof(*pHeader) | 0x1); pHeader->usPathLength = SMB_HTOL16(ulPathLength * sizeof(WCHAR)); /* Align to WCHAR */ status = Align((PBYTE) pPacket->pSMB2Header, ppCursor, pulRemaining, sizeof(WCHAR)); BAIL_ON_NT_STATUS(status); pFilename = *ppCursor; /* Fill in offset field */ pHeader->usPathOffset = SMB_HTOL16((USHORT) PACKET_HEADER_OFFSET(pPacket, pFilename)); /* Fill in data */ status = Advance(ppCursor, pulRemaining, ulPathLength * sizeof(WCHAR)); BAIL_ON_NT_STATUS(status); SMB_HTOLWSTR( pFilename, pwszPath, ulPathLength); BAIL_ON_NT_STATUS(status); cleanup: return status; error: goto cleanup; }
/** * Append an item and return it. * @param to_add the number of items to append * @return pointer to newly allocated item */ FORCEINLINE T *Append(uint to_add = 1) { uint begin = this->items; this->items += to_add; if (this->items > this->capacity) { this->capacity = Align(this->items, S); this->data = ReallocT(this->data, this->capacity); } return &this->data[begin]; }
/** * Pads a specified number of bytes to the memory writer to maintain alignment */ void PadMemoryWriter(FMemoryWriter* MemoryWriter, uint8*& TrackData, const int32 Alignment) { const PTRINT ByteStreamLoc = (PTRINT) TrackData; const int32 Pad = static_cast<int32>( Align( ByteStreamLoc, Alignment ) - ByteStreamLoc ); const uint8 PadSentinel = 85; // (1<<1)+(1<<3)+(1<<5)+(1<<7) for ( int32 PadByteIndex = 0; PadByteIndex < Pad; ++PadByteIndex ) { MemoryWriter->Serialize( (void*)&PadSentinel, sizeof(uint8) ); } TrackData += Pad; }
/** * Resizes the pool so 'index' can be addressed * @param index index we will allocate later * @pre index >= this->size * @pre index < Tmax_size */ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index) { assert(index >= this->size); assert(index < Tmax_size); size_t new_size = ::min(Tmax_size, Align(index + 1, Tgrowth_step)); this->data = ReallocT(this->data, new_size); MemSetT(this->data + this->size, 0, new_size - this->size); this->size = new_size; }
/// <summary> /// Allocate stack variable /// </summary> /// <param name="size">Variable size</param> /// <returns>Variable memory object</returns> AsmJit::Mem AllocVar( intptr_t size ) { // Align on word length size = Align( size, sizeof(size_t) ); #ifdef _M_AMD64 auto val = AsmJit::Mem( AsmJit::nsp, disp_ofst, size ); #else auto val = AsmJit::Mem( AsmJit::nbp, -disp_ofst - size, size ); #endif disp_ofst += size; return val; }
HRESULT DataTargetReader::Read(TargetObject* pTargetObject) { ULONG32 previousAlign = m_currentStructureAlign; m_currentStructureAlign = 1; HRESULT hr = pTargetObject->ReadFrom(*this); if (SUCCEEDED(hr)) { // increase the structure size to a multiple of the maximum alignment of any of its members Align(m_currentStructureAlign); } m_currentStructureAlign = MAX(previousAlign, m_currentStructureAlign); return hr; }
/// <summary> /// Allocate stack variable /// </summary> /// <param name="size">Variable size</param> /// <returns>Variable memory object</returns> asmjit::host::Mem AllocVar( intptr_t size ) { // Align on word length size = Align( size, sizeof(size_t) ); #ifdef USE64 auto val = asmjit::host::Mem( asmjit::host::zsp, static_cast<int32_t>(disp_ofst), static_cast<int32_t>(size) ); #else auto val = asmjit::host::Mem( asmjit::host::zbp, -disp_ofst - size, size ); #endif disp_ofst += size; return val; }
bool CopyFileToPak(FArchive& InPak, const FString& InMountPoint, const FPakInputPair& InFile, uint8*& InOutPersistentBuffer, int64& InOutBufferSize, FPakEntryPair& OutNewEntry) { TAutoPtr<FArchive> FileHandle(IFileManager::Get().CreateFileReader(*InFile.Source)); bool bFileExists = FileHandle.IsValid(); if (bFileExists) { const int64 FileSize = FileHandle->TotalSize(); const int64 PaddedEncryptedFileSize = Align(FileSize, FAES::AESBlockSize); OutNewEntry.Filename = InFile.Dest.Mid(InMountPoint.Len()); OutNewEntry.Info.Offset = 0; // Don't serialize offsets here. OutNewEntry.Info.Size = FileSize; OutNewEntry.Info.UncompressedSize = FileSize; OutNewEntry.Info.CompressionMethod = COMPRESS_None; OutNewEntry.Info.bEncrypted = InFile.bNeedEncryption; if (InOutBufferSize < PaddedEncryptedFileSize) { InOutPersistentBuffer = (uint8*)FMemory::Realloc(InOutPersistentBuffer, PaddedEncryptedFileSize); InOutBufferSize = FileSize; } // Load to buffer FileHandle->Serialize(InOutPersistentBuffer, FileSize); { int64 SizeToWrite = FileSize; if (InFile.bNeedEncryption) { for(int64 FillIndex=FileSize; FillIndex < PaddedEncryptedFileSize && InFile.bNeedEncryption; ++FillIndex) { // Fill the trailing buffer with random bytes from file InOutPersistentBuffer[FillIndex] = InOutPersistentBuffer[rand()%FileSize]; } //Encrypt the buffer before writing it to disk FAES::EncryptData(InOutPersistentBuffer, PaddedEncryptedFileSize); // Update the size to be written SizeToWrite = PaddedEncryptedFileSize; OutNewEntry.Info.bEncrypted = true; } // Calculate the buffer hash value FSHA1::HashBuffer(InOutPersistentBuffer,FileSize,OutNewEntry.Info.Hash); // Write to file OutNewEntry.Info.Serialize(InPak,FPakInfo::PakFile_Version_Latest); InPak.Serialize(InOutPersistentBuffer,SizeToWrite); } } return bFileExists; }
/// <summary> /// Allocates memory region beyond 4GB limit /// </summary> /// <param name="imageMem">Image data</param> /// <param name="size">Block size</param> /// <returns>true on success</returns> bool MMap::AllocateInHighMem( MemBlock& imageMem, size_t size ) { HANDLE hFile = GetDriverHandle(); if (hFile != INVALID_HANDLE_VALUE) { ptr_t ptr = 0; // Align on page boundary size = Align( size, 0x1000 ); // // Get random address // bool found = true; static std::random_device rd; std::uniform_int_distribution<ptr_t> dist( 0x100000, 0x7FFFFFFF ); // Make sure address is unused for (ptr = dist( rd ) * 0x1000; found; ptr = dist( rd ) * 0x1000) { found = false; for (auto& entry : _usedBlocks) if (ptr >= entry.first && ptr < entry.first + entry.second) { found = true; break; } } PURGE_DATA data = { _process.core().pid(), 1, { ptr, size } }; DWORD junk = 0; BOOL ret = DeviceIoControl( hFile, static_cast<DWORD>(IOCTL_VADPURGE_ENABLECHANGE), &data, sizeof(data), NULL, 0, &junk, NULL ); CloseHandle( hFile ); // Change protection and save address if(ret == TRUE) { _usedBlocks.emplace_back( std::make_pair( ptr, size ) ); imageMem = MemBlock( &_process.memory(), ptr, size, PAGE_READWRITE, false ); _process.memory( ).Protect( ptr, size, PAGE_READWRITE ); return true; } } return false; }
void DefineCommData(Symbol p) { Align(p); GetAccessName(p); if (p->sclass == TK_STATIC) { Print("%s\t", p->aname); Space(p->ty->size); } else { Print("COMM\t%s:%d\n", p->aname, p->ty->size); } }
bool MemPage::extend(RadixHeapBlock *block,ulen blen) { ulen len=block->len; blen=Align(blen,Sys::MemPageLen); if( blen<=len ) return false; if( !Sys::MemPageExtend(block,len/Sys::MemPageLen,(blen-len)/Sys::MemPageLen) ) return false; block->init(blen); return true; }
/// \brief Reallocates internal block to hold at least \p newSize bytes. /// /// Additional memory may be allocated, but for efficiency it is a very /// good idea to call reserve before doing byte-by-byte edit operations. /// The block size as returned by size() is not altered. reserve will not /// reduce allocated memory. If you think you are wasting space, call /// deallocate and start over. To avoid wasting space, use the block for /// only one purpose, and try to get that purpose to use similar amounts /// of memory on each iteration. /// void memblock::reserve (size_type newSize, bool bExact) { if ((newSize += minimumFreeCapacity()) <= m_Capacity) return; void* oldBlock (is_linked() ? NULL : data()); if (!bExact) newSize = Align (newSize, c_PageSize); pointer newBlock = (pointer) realloc (oldBlock, newSize); if (!newBlock) __THROW_BAD_ALLOC(newSize); if (!oldBlock && cdata()) copy_n (cdata(), min (size() + 1, newSize), newBlock); link (newBlock, size()); m_Capacity = newSize; }
//-------------------------------------------------------------------------------------- // // SuballocateFromUploadHeap // //-------------------------------------------------------------------------------------- UINT8* UploadHeapDX12::Suballocate(SIZE_T uSize, UINT64 uAlign) { m_pDataCur = reinterpret_cast<UINT8*>(Align(reinterpret_cast<SIZE_T>(m_pDataCur), uAlign)); // flush operations if we ran out of space in the heap if (m_pDataCur >= m_pDataEnd || m_pDataCur + uSize >= m_pDataEnd) { FlushAndFinish(); } UINT8* pRet = m_pDataCur; m_pDataCur += uSize; return pRet; }