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
- StringStorage.cs
- PtsContext.cs
- ConnectionModeReader.cs
- KeyFrames.cs
- PasswordPropertyTextAttribute.cs
- XamlFigureLengthSerializer.cs
- SqlDependencyUtils.cs
- Propagator.Evaluator.cs
- CapabilitiesAssignment.cs
- RootProfilePropertySettingsCollection.cs
- HtmlForm.cs
- NativeMethods.cs
- CommentGlyph.cs
- TextServicesProperty.cs
- ClientBuildManager.cs
- DiscoveryVersion.cs
- GridItem.cs
- XmlSchemaInfo.cs
- ParallelQuery.cs
- CookieProtection.cs
- UTF7Encoding.cs
- PropertyDescriptorComparer.cs
- RegistryPermission.cs
- DtdParser.cs
- StrongName.cs
- PathFigureCollection.cs
- IDictionary.cs
- WebServicesSection.cs
- PrintingPermission.cs
- VectorValueSerializer.cs
- Debug.cs
- Nullable.cs
- StateRuntime.cs
- BatchParser.cs
- SystemMulticastIPAddressInformation.cs
- LabelAutomationPeer.cs
- FaultDescription.cs
- NaturalLanguageHyphenator.cs
- ClientRuntime.cs
- XmlSchemaIdentityConstraint.cs
- Label.cs
- SchemaHelper.cs
- ToolStripPanelRenderEventArgs.cs
- AppSettingsSection.cs
- TailCallAnalyzer.cs
- TypeDescriptionProviderAttribute.cs
- UIElementPropertyUndoUnit.cs
- UnsafeNativeMethodsCLR.cs
- DeclaredTypeElementCollection.cs
- TransformGroup.cs
- CodeChecksumPragma.cs
- EntityDataSourceContextDisposingEventArgs.cs
- SqlXmlStorage.cs
- OracleEncoding.cs
- LinqDataView.cs
- FixedSOMGroup.cs
- Triplet.cs
- CodeAttachEventStatement.cs
- SimpleTextLine.cs
- _ContextAwareResult.cs
- QilReplaceVisitor.cs
- QEncodedStream.cs
- AccessViolationException.cs
- MailWebEventProvider.cs
- hwndwrapper.cs
- OleDbSchemaGuid.cs
- TakeOrSkipQueryOperator.cs
- DbRetry.cs
- OdbcParameter.cs
- XmlSchemaElement.cs
- FixedSOMTable.cs
- ElementHost.cs
- ObjectDesignerDataSourceView.cs
- DBSchemaRow.cs
- ComPersistableTypeElement.cs
- XmlNamespaceMappingCollection.cs
- GridProviderWrapper.cs
- HandleCollector.cs
- WebZone.cs
- CompositeKey.cs
- CodeDOMUtility.cs
- GridItemCollection.cs
- ListGeneralPage.cs
- OperationAbortedException.cs
- InternalReceiveMessage.cs
- DocumentPageView.cs
- HttpWebResponse.cs
- OpCodes.cs
- DirectionalLight.cs
- StorageBasedPackageProperties.cs
- SearchForVirtualItemEventArgs.cs
- WebEventCodes.cs
- GCHandleCookieTable.cs
- TrustManagerMoreInformation.cs
- GeneralTransform3D.cs
- DataGridViewHeaderCell.cs
- StringValueSerializer.cs
- PartitionResolver.cs
- CodeMethodReturnStatement.cs
- OperationValidationEventArgs.cs