public static DbItemReference CreateNew(byte[] body, int transactionNumber, IMemoryManager memoryManager) { if (body == null) { throw new ArgumentNullException(nameof(body)); } if (memoryManager == null) { throw new ArgumentNullException(nameof(memoryManager)); } var bodyReference = memoryManager.Allocate(body); var versionInfo = new VersionInfo { CreateChangeNumber = transactionNumber, ExpireChangeNumber = -1, VersionReference = bodyReference }; byte[] versionInfoBytes; using (var ms = new MemoryStream(VersionInfo.BytesLength)) { versionInfo.Write(ms); versionInfoBytes = ms.ToArray(); } return(memoryManager.Allocate(versionInfoBytes)); }
public DbItemReference AllocateNew() { byte[] versionInfoBytes; using (var ms = new MemoryStream(VersionInfo.BytesLength * _versions.Count)) { foreach (var v in _versions) { v.Write(ms); } versionInfoBytes = ms.ToArray(); } return(_memoryManager.Allocate(versionInfoBytes)); }
/// <summary> /// Allocates a new value and produces reference to it. /// </summary> /// <param name="value">Value to allocate</param> /// <returns>Reference to allocated value</returns> public DbItemReference AllocateNew(TValue value) { var valueBytes = _valueSerializer.Serialize(value); return(IsVersioningEnabled ? VersionedRecord.CreateNew(valueBytes, DataTankerTransaction.Current.Id, _memoryManager) : _memoryManager.Allocate(valueBytes)); }
private IntPtr ExecuteFuntion(string module, string function, byte[] arguments, bool canWait = true) { SafeWaitHandle remoteThread = null; var argumentsAllocation = _memoryManager.Allocate( arguments.Length, MemoryProtectionType.ReadWrite, !canWait); if (argumentsAllocation.Address == IntPtr.Zero) { throw new Win32Exception("Failed to allocate memory in remote process."); } try { var processHandle = _process.SafeHandle; // Write the arguments buffer to our allocated address _memoryManager.WriteMemory(argumentsAllocation.Address.ToInt64(), arguments); // Execute the function call in a new thread remoteThread = ThreadHelper.CreateRemoteThread(processHandle, ThreadHelper.GetProcAddress(processHandle, module, function), argumentsAllocation.Address); if (canWait) { Interop.Kernel32.WaitForSingleObject( remoteThread, System.Threading.Timeout.Infinite); } return(argumentsAllocation.Address); } finally { remoteThread?.Dispose(); if (canWait) { _memoryManager.Deallocate(argumentsAllocation); } } }