internal void CopyTo(CheckedPointer dest) { unsafe { if (_pointer == null) { throw new ArgumentOutOfRangeException(); } byte *s = (byte *)_pointer; byte *d = (byte *)dest.Probe(0, _size); for (int i = 0; i < _size; ++i) { d[i] = s[i]; } } }
internal void InitFromCacheImage(CheckedPointer cacheImage) { if (cacheImage.Size < MinCacheSize || (cacheImage.Size % 8) != 0 || cacheImage.Size > MaxCacheSize) { // Malformed input cache, just return. Assert in debug builds to catch possible bugs. Debug.Assert(false); return; } int oldCurrentSize; unsafe { // Validate the current size field in the existing cache image. oldCurrentSize = *(int *)cacheImage.Probe(offCurSize, sizeof(int)); } if (Util.Align8(oldCurrentSize) != oldCurrentSize || oldCurrentSize != cacheImage.Size) { // Malformed input cache, just return. Assert in debug builds to catch possible bugs. Debug.Assert(false); return; } _mfile.Commit(cacheImage.Size); GetCacheHeader()->CurSize = cacheImage.Size; cacheImage.CopyTo(Mapping); // This can happen only if the current cache size field was not set properly in the cache image, // and we should have caught this situation earlier in this function. Invariant.Assert(CurrentSize == cacheImage.Size); SetNew(); }