MemCpy() public static method

Copies contents of src buffer to dest buffer, as efficiently as possible.
public static MemCpy ( [ src, [ dest, int len ) : void
src [ Source array/pointer.
dest [ Destination array/pointer.
len int Number of bytes to copy.
return void
示例#1
0
        void Preload()
        {
            using (FileStream fs = OpenRead()) {
                CacheSize = (int)(fs.Length / BlockDBEntry.Size);
                EnsureCapacity(CacheSize);
                LastFlushedIndex = CacheSize;

                // Converting from byte[] to BlockDBEntry[] on the fly
                // This is possible because BlockDBEntry is a sequentially packed struct
                fixed(BlockDBEntry *pCacheStart = cacheStore)
                {
                    fixed(byte *pBuffer = ioBuffer)
                    {
                        byte *pCache = (byte *)pCacheStart;

                        while (fs.Position < fs.Length)
                        {
                            int bytesToRead   = Math.Min(BufferSize, (int)(fs.Length - fs.Position));
                            int bytesInBuffer = 0;
                            do
                            {
                                int bytesRead = fs.Read(ioBuffer, bytesInBuffer, BufferSize - bytesInBuffer);
                                bytesInBuffer += bytesRead;
                            } while(bytesInBuffer < bytesToRead);
                            BufferUtil.MemCpy(pBuffer, pCache, bytesInBuffer);
                            pCache += bytesInBuffer;
                        }
                    }
                }
            }
        }