本文整理汇总了C#中BufferManager.TakeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# BufferManager.TakeBuffer方法的具体用法?C# BufferManager.TakeBuffer怎么用?C# BufferManager.TakeBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferManager
的用法示例。
在下文中一共展示了BufferManager.TakeBuffer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendPayloadAsHeader
public static ArraySegment<byte> AppendPayloadAsHeader(ArraySegment<byte> buffer, ArraySegment<byte> payload, BufferManager bufferManager)
{
// We will insert at the beginning of the buffer just before the dictionary or any message content
int posToInsert = buffer.Offset;
int frameSize = PayloadMarkLength + PayloadLengthByteCount + payload.Count;
byte[] newBuffer = bufferManager.TakeBuffer(buffer.Count + frameSize + buffer.Offset);
int afterContent = posToInsert + frameSize;
// Insert our custom mark 0xBE
int insertPoint = posToInsert;
newBuffer[insertPoint++] = PayloadMark;
// Insert the length of the payload
byte[] lenInBytes = BitConverter.GetBytes(payload.Count);
newBuffer[insertPoint++] = lenInBytes[0];
newBuffer[insertPoint++] = lenInBytes[1];
newBuffer[insertPoint++] = lenInBytes[2];
newBuffer[insertPoint++] = lenInBytes[3];
Buffer.BlockCopy(payload.Array, payload.Offset, newBuffer, insertPoint, payload.Count);
// Copy from old to new array
Buffer.BlockCopy(buffer.Array, 0, newBuffer, 0, posToInsert); // Copy until the subheader pointer
Buffer.BlockCopy(buffer.Array, posToInsert, newBuffer, afterContent, buffer.Count - posToInsert + buffer.Offset); // Now copy the rest
return new ArraySegment<byte>(newBuffer, buffer.Offset, buffer.Count + frameSize);
}
示例2: BitmapManager
public BitmapManager(BufferManager bufferManager)
{
_bitmapStream = new BufferStream(bufferManager);
_bufferManager = bufferManager;
_cacheBuffer = _bufferManager.TakeBuffer(BitmapManager.SectorSize);
}
示例3: BinaryArray
public BinaryArray(int length, BufferManager bufferManager)
{
_length = length;
_bufferManager = bufferManager;
_buffer = _bufferManager.TakeBuffer((int)BinaryArray.Roundup(_length, 8));
Unsafe.Zero(_buffer);
}
示例4: BinaryArray
public BinaryArray(int length, BufferManager bufferManager)
{
_length = length;
_bufferManager = bufferManager;
_buffer = _bufferManager.TakeBuffer((_length + (8 - 1)) / 8);
Unsafe.Zero(_buffer);
}
示例5: CacheManagerStreamWriter
public CacheManagerStreamWriter(out KeyCollection keys, int blockLength, HashAlgorithm hashAlgorithm, CacheManager cacheManager, BufferManager bufferManager)
{
keys = _keyList;
_hashAlgorithm = hashAlgorithm;
_cacheManager = cacheManager;
_bufferManager = bufferManager;
_blockBuffer = bufferManager.TakeBuffer(blockLength);
_blockBufferLength = blockLength;
}
示例6: UnbufferedFileStream
public UnbufferedFileStream(string path, FileMode mode, FileAccess access, FileShare share, FileOptions options, BufferManager bufferManager)
{
_path = path;
_bufferManager = bufferManager;
{
const FileOptions FileFlagNoBuffering = (FileOptions)0x20000000;
_stream = new FileStream(path, mode, access, share, 8, options | FileFlagNoBuffering);
}
_blockInfo = new BlockInfo();
{
_blockInfo.IsUpdated = false;
_blockInfo.Position = -1;
_blockInfo.Offset = 0;
_blockInfo.Count = 0;
_blockInfo.Value = _bufferManager.TakeBuffer(SectorSize);
}
_position = _stream.Position;
_length = _stream.Length;
}
示例7: Compress
public static void Compress(Stream inStream, Stream outStream, BufferManager bufferManager)
{
var info = new ProcessStartInfo(_path);
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardInput = true;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.Arguments = "--compress --format=lzma -4 --threads=1 --stdout";
using (var inCacheStream = new CacheStream(inStream, 1024 * 32, bufferManager))
using (var outCacheStream = new CacheStream(outStream, 1024 * 32, bufferManager))
{
using (Process process = Process.Start(info))
{
process.PriorityClass = ProcessPriorityClass.Idle;
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
{
Log.Error(e.Data);
};
Exception threadException = null;
var thread = new Thread(new ThreadStart(() =>
{
try
{
byte[] buffer = bufferManager.TakeBuffer(1024 * 32);
try
{
using (var standardOutputStream = process.StandardOutput.BaseStream)
{
int length = 0;
while ((length = standardOutputStream.Read(buffer, 0, buffer.Length)) > 0)
{
outCacheStream.Write(buffer, 0, length);
}
}
}
finally
{
bufferManager.ReturnBuffer(buffer);
}
}
catch (Exception e)
{
threadException = e;
}
}));
thread.IsBackground = true;
thread.Start();
try
{
byte[] buffer = bufferManager.TakeBuffer(1024 * 32);
try
{
using (var standardInputStream = process.StandardInput.BaseStream)
{
int length = 0;
while ((length = inCacheStream.Read(buffer, 0, buffer.Length)) > 0)
{
standardInputStream.Write(buffer, 0, length);
}
}
}
finally
{
bufferManager.ReturnBuffer(buffer);
}
}
catch (Exception)
{
throw;
}
thread.Join();
if (threadException != null) throw threadException;
process.WaitForExit();
}
}
}