Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Internal / HGlobalSafeHandle.cs / 1 / HGlobalSafeHandle.cs
//---------------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // // Description: // Stream Helper. // Allocates a global memory buffer to do marshaling between a // binary and a structured data. The global memory size increases and // never shrinks. // using System; using System.Runtime.InteropServices; namespace System.Speech.Internal { ////// Encapsulate SafeHandle for Win32 Memory Handles /// internal sealed class HGlobalSafeHandle : SafeHandle { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors internal HGlobalSafeHandle () : base (IntPtr.Zero, true) { } // This destructor will run only if the Dispose method // does not get called. ~HGlobalSafeHandle () { Dispose (false); } protected override void Dispose (bool disposing) { ReleaseHandle (); base.Dispose (disposing); GC.SuppressFinalize (this); } #endregion //******************************************************************** // // Internal Methods // //******************************************************************* #region internal Methods ////// /// /// ///internal IntPtr Buffer (int size) { if (size > _bufferSize) { if (_bufferSize == 0) { SetHandle (Marshal.AllocHGlobal (size)); } else { SetHandle (Marshal.ReAllocHGlobal (handle, (IntPtr) size)); } GC.AddMemoryPressure (size - _bufferSize); _bufferSize = size; } return handle; } /// /// True if the no memory is allocated /// ///public override bool IsInvalid { get { return handle == IntPtr.Zero; } } #endregion //******************************************************************** // // Protected Methods // //******************************************************************** #region Protected Methods /// /// Releases the Win32 Memory handle /// ///protected override bool ReleaseHandle () { if (handle != IntPtr.Zero) { // Reset the extra information given to the GC if (_bufferSize > 0) { GC.RemoveMemoryPressure (_bufferSize); _bufferSize = 0; } Marshal.FreeHGlobal (handle); handle = IntPtr.Zero; return true; } return false; } #endregion //******************************************************************* // // Private Fields // //******************************************************************** #region Private Fields private int _bufferSize; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // // Description: // Stream Helper. // Allocates a global memory buffer to do marshaling between a // binary and a structured data. The global memory size increases and // never shrinks. // using System; using System.Runtime.InteropServices; namespace System.Speech.Internal { ////// Encapsulate SafeHandle for Win32 Memory Handles /// internal sealed class HGlobalSafeHandle : SafeHandle { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors internal HGlobalSafeHandle () : base (IntPtr.Zero, true) { } // This destructor will run only if the Dispose method // does not get called. ~HGlobalSafeHandle () { Dispose (false); } protected override void Dispose (bool disposing) { ReleaseHandle (); base.Dispose (disposing); GC.SuppressFinalize (this); } #endregion //******************************************************************** // // Internal Methods // //******************************************************************* #region internal Methods ////// /// /// ///internal IntPtr Buffer (int size) { if (size > _bufferSize) { if (_bufferSize == 0) { SetHandle (Marshal.AllocHGlobal (size)); } else { SetHandle (Marshal.ReAllocHGlobal (handle, (IntPtr) size)); } GC.AddMemoryPressure (size - _bufferSize); _bufferSize = size; } return handle; } /// /// True if the no memory is allocated /// ///public override bool IsInvalid { get { return handle == IntPtr.Zero; } } #endregion //******************************************************************** // // Protected Methods // //******************************************************************** #region Protected Methods /// /// Releases the Win32 Memory handle /// ///protected override bool ReleaseHandle () { if (handle != IntPtr.Zero) { // Reset the extra information given to the GC if (_bufferSize > 0) { GC.RemoveMemoryPressure (_bufferSize); _bufferSize = 0; } Marshal.FreeHGlobal (handle); handle = IntPtr.Zero; return true; } return false; } #endregion //******************************************************************* // // Private Fields // //******************************************************************** #region Private Fields private int _bufferSize; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebPartDescriptionCollection.cs
- MoveSizeWinEventHandler.cs
- ListSortDescription.cs
- WmpBitmapDecoder.cs
- SafeNativeMethodsOther.cs
- SvcMapFileLoader.cs
- ReadOnlyHierarchicalDataSourceView.cs
- AttributeQuery.cs
- IpcClientManager.cs
- CompilerInfo.cs
- Vector3DCollectionConverter.cs
- FilterableData.cs
- BufferedStream.cs
- EntityCommandDefinition.cs
- Model3DGroup.cs
- PersistenceProviderFactory.cs
- ConnectionManagementElement.cs
- WorkflowMessageEventHandler.cs
- PenLineJoinValidation.cs
- ExtentCqlBlock.cs
- Convert.cs
- CreateUserErrorEventArgs.cs
- Listbox.cs
- ConfigErrorGlyph.cs
- WpfSharedBamlSchemaContext.cs
- QueryExpr.cs
- SqlBulkCopyColumnMapping.cs
- SpecularMaterial.cs
- NativeCppClassAttribute.cs
- Perspective.cs
- CompressStream.cs
- MiniModule.cs
- ListView.cs
- ThemeDirectoryCompiler.cs
- TextTreeInsertUndoUnit.cs
- AddInAttribute.cs
- KeyedQueue.cs
- StartUpEventArgs.cs
- ShaderEffect.cs
- PaintEvent.cs
- CodeCastExpression.cs
- BindingMAnagerBase.cs
- InlineUIContainer.cs
- OrderByQueryOptionExpression.cs
- AsymmetricKeyExchangeFormatter.cs
- XmlAttributes.cs
- ProcessInfo.cs
- Latin1Encoding.cs
- SoapReflectionImporter.cs
- Stacktrace.cs
- LayoutEditorPart.cs
- CodeIndexerExpression.cs
- lengthconverter.cs
- ButtonField.cs
- AutoGeneratedField.cs
- TransactionScope.cs
- WorkflowItemsPresenter.cs
- SizeAnimation.cs
- QilList.cs
- Timer.cs
- WindowsStatusBar.cs
- RegexParser.cs
- NumberSubstitution.cs
- MarkerProperties.cs
- ScopelessEnumAttribute.cs
- ping.cs
- WebReferencesBuildProvider.cs
- QuaternionRotation3D.cs
- EventDescriptor.cs
- TextTrailingWordEllipsis.cs
- SignedInfo.cs
- CodeExporter.cs
- ContextProperty.cs
- TypeUnloadedException.cs
- ListViewInsertEventArgs.cs
- EventLogPermissionAttribute.cs
- XmlSchemaAny.cs
- IConvertible.cs
- XmlLanguageConverter.cs
- LinqDataSourceUpdateEventArgs.cs
- Visual3D.cs
- XmlSchemaObjectCollection.cs
- Size3D.cs
- VolatileEnlistmentMultiplexing.cs
- PropertyPathWorker.cs
- XLinq.cs
- ICollection.cs
- QuerySubExprEliminator.cs
- RubberbandSelector.cs
- ParenthesizePropertyNameAttribute.cs
- FromRequest.cs
- FamilyTypeface.cs
- HostExecutionContextManager.cs
- SqlDataSourceWizardForm.cs
- MenuItemCollection.cs
- CompoundFileDeflateTransform.cs
- DiscreteKeyFrames.cs
- RowCache.cs
- X509IssuerSerialKeyIdentifierClause.cs
- DataServiceRequestOfT.cs