Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / clr / src / BCL / System / IO / PinnedBufferMemoryStream.cs / 1 / PinnedBufferMemoryStream.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: PinnedBufferMemoryStream ** ** ** Purpose: Pins a byte[], exposing it as an unmanaged memory ** stream. Used in ResourceReader for corner cases. ** ** ===========================================================*/ using System; using System.Runtime.InteropServices; namespace System.IO { internal sealed unsafe class PinnedBufferMemoryStream : UnmanagedMemoryStream { private byte[] _array; private GCHandle _pinningHandle; internal PinnedBufferMemoryStream(byte[] array) { BCLDebug.Assert(array != null, "Array can't be null"); int len = array.Length; // Handle 0 length byte arrays specially. if (len == 0) { array = new byte[1]; len = 0; } _array = array; _pinningHandle = new GCHandle(array, GCHandleType.Pinned); // Now the byte[] is pinned for the lifetime of this instance. // But I also need to get a pointer to that block of memory... fixed(byte* ptr = _array) Initialize(ptr, len, len, FileAccess.Read, true); } ~PinnedBufferMemoryStream() { Dispose(false); } protected override void Dispose(bool disposing) { if (_isOpen) { _pinningHandle.Free(); _isOpen = false; } #if _DEBUG // To help track down lifetime issues on checked builds, force //a full GC here. if (disposing) { GC.Collect(); GC.WaitForPendingFinalizers(); } #endif base.Dispose(disposing); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListParagraph.cs
- HtmlTable.cs
- OleDbCommand.cs
- InfoCardKeyedHashAlgorithm.cs
- Clause.cs
- CodeDirectoryCompiler.cs
- ImageAttributes.cs
- ServiceNameElement.cs
- PointLightBase.cs
- Claim.cs
- SoapWriter.cs
- ISAPIApplicationHost.cs
- configsystem.cs
- FtpWebResponse.cs
- EncodingFallbackAwareXmlTextWriter.cs
- handlecollector.cs
- Root.cs
- ImagingCache.cs
- EncryptedKeyIdentifierClause.cs
- ServiceMoniker.cs
- DTCTransactionManager.cs
- ReferencedType.cs
- CodeVariableReferenceExpression.cs
- FixedSOMImage.cs
- DbSetClause.cs
- HwndSubclass.cs
- TriggerActionCollection.cs
- ServiceModelStringsVersion1.cs
- Simplifier.cs
- RandomNumberGenerator.cs
- FileNameEditor.cs
- DbParameterHelper.cs
- SimpleType.cs
- DesignerSerializationVisibilityAttribute.cs
- StreamUpgradeAcceptor.cs
- DecoratedNameAttribute.cs
- Label.cs
- Rect.cs
- DrawingVisualDrawingContext.cs
- WindowsGraphicsWrapper.cs
- EdgeModeValidation.cs
- DateBoldEvent.cs
- ViewManagerAttribute.cs
- TraceLevelStore.cs
- ProcessProtocolHandler.cs
- ClientOptions.cs
- ObjectComplexPropertyMapping.cs
- SqlProvider.cs
- TriggerAction.cs
- LogSwitch.cs
- ApplicationBuildProvider.cs
- Label.cs
- DropDownList.cs
- FontSource.cs
- AuthorizationPolicyTypeElement.cs
- InputScopeConverter.cs
- SiteMapNodeItemEventArgs.cs
- XmlAtomErrorReader.cs
- GlyphInfoList.cs
- DataGridViewCellStyleConverter.cs
- DataSourceSerializationException.cs
- SqlCacheDependency.cs
- UIElementParagraph.cs
- SoapExtension.cs
- DataRow.cs
- Icon.cs
- RequiredFieldValidator.cs
- RichTextBoxAutomationPeer.cs
- SafeProcessHandle.cs
- SizeChangedEventArgs.cs
- StylusPointPropertyInfo.cs
- QueryExpression.cs
- loginstatus.cs
- BamlTreeUpdater.cs
- ZipIOBlockManager.cs
- SiteMapDataSourceView.cs
- MobileRedirect.cs
- ArrayList.cs
- __Error.cs
- QilScopedVisitor.cs
- BinaryUtilClasses.cs
- CaseStatement.cs
- FileAuthorizationModule.cs
- BodyGlyph.cs
- ScriptModule.cs
- MouseOverProperty.cs
- NeutralResourcesLanguageAttribute.cs
- QueueProcessor.cs
- SrgsElementList.cs
- TableAutomationPeer.cs
- TypeInfo.cs
- Brush.cs
- PerformanceCounterPermissionEntry.cs
- ParameterBinding.cs
- DataSetMappper.cs
- PostBackOptions.cs
- FormViewCommandEventArgs.cs
- ListParaClient.cs
- StringBuilder.cs
- StackBuilderSink.cs