コード例 #1
0
ファイル: SpanByte.cs プロジェクト: rustedwizard/FASTER
        /// <summary>
        /// Copy to given SpanByteAndMemory (header and payload copied to actual span/memory)
        /// </summary>
        /// <param name="dst"></param>
        /// <param name="memoryPool"></param>
        public void CopyWithHeaderTo(ref SpanByteAndMemory dst, MemoryPool <byte> memoryPool)
        {
            if (dst.IsSpanByte)
            {
                if (dst.Length >= TotalSize)
                {
                    dst.Length = TotalSize;
                    var span = dst.SpanByte.AsSpan();

                    fixed(byte *ptr = span)
                    * (int *)ptr = Length;

                    AsReadOnlySpan().CopyTo(span.Slice(sizeof(int)));
                    return;
                }
                dst.ConvertToHeap();
            }

            dst.Memory = memoryPool.Rent(TotalSize);
            dst.Length = TotalSize;

            fixed(byte *ptr = dst.Memory.Memory.Span)
            * (int *)ptr = Length;

            AsReadOnlySpan().CopyTo(dst.Memory.Memory.Span.Slice(sizeof(int)));
        }
コード例 #2
0
ファイル: SpanByte.cs プロジェクト: rustedwizard/FASTER
        /// <summary>
        /// Copy to given SpanByteAndMemory (only payload copied to actual span/memory)
        /// </summary>
        /// <param name="dst"></param>
        /// <param name="memoryPool"></param>
        public void CopyTo(ref SpanByteAndMemory dst, MemoryPool <byte> memoryPool)
        {
            if (dst.IsSpanByte)
            {
                if (dst.Length >= Length)
                {
                    dst.Length = Length;
                    AsReadOnlySpan().CopyTo(dst.SpanByte.AsSpan());
                    return;
                }
                dst.ConvertToHeap();
            }

            dst.Memory = memoryPool.Rent(Length);
            dst.Length = Length;
            AsReadOnlySpan().CopyTo(dst.Memory.Memory.Span);
        }