Code:
/ DotNET / DotNET / 8.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Slider.cs
- ElementsClipboardData.cs
- TypeRefElement.cs
- BitmapEffectInput.cs
- UpdateProgress.cs
- LabelEditEvent.cs
- DbSetClause.cs
- LocatorPart.cs
- DataRelation.cs
- XmlSchemaComplexType.cs
- XsltSettings.cs
- DesignTimeTemplateParser.cs
- OdbcDataReader.cs
- ProxyWebPart.cs
- CapabilitiesState.cs
- WebConfigurationFileMap.cs
- GifBitmapDecoder.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- LicenseException.cs
- SafeCloseHandleCritical.cs
- PointAnimationUsingKeyFrames.cs
- StorageEndPropertyMapping.cs
- IpcPort.cs
- DataGridViewMethods.cs
- PrivilegedConfigurationManager.cs
- MissingFieldException.cs
- xml.cs
- XmlCompatibilityReader.cs
- PageParserFilter.cs
- DeviceSpecific.cs
- AuthenticationException.cs
- PingReply.cs
- ControlDesignerState.cs
- DataFormats.cs
- DebugInfo.cs
- PersonalizationStateInfo.cs
- NamespaceQuery.cs
- DataGridViewCellEventArgs.cs
- UnmanagedBitmapWrapper.cs
- ContentValidator.cs
- ButtonFieldBase.cs
- ObjectPersistData.cs
- ImageFormatConverter.cs
- ConfigXmlWhitespace.cs
- NonParentingControl.cs
- ResourcePermissionBaseEntry.cs
- UTF32Encoding.cs
- TimeSpan.cs
- Menu.cs
- ObservableCollection.cs
- RuntimeConfigLKG.cs
- GridSplitter.cs
- CatalogPartChrome.cs
- WebZone.cs
- NativeMethods.cs
- Lasso.cs
- PlatformNotSupportedException.cs
- TextPointer.cs
- documentsequencetextcontainer.cs
- EntityDataSourceWrapper.cs
- StorageComplexTypeMapping.cs
- LogicalTreeHelper.cs
- TableHeaderCell.cs
- TextDecorations.cs
- GregorianCalendar.cs
- MLangCodePageEncoding.cs
- EditingScopeUndoUnit.cs
- ValidationEventArgs.cs
- PathGradientBrush.cs
- RemoteWebConfigurationHost.cs
- WebReferenceOptions.cs
- MetadataArtifactLoaderResource.cs
- FormatVersion.cs
- Site.cs
- MethodBody.cs
- CleanUpVirtualizedItemEventArgs.cs
- Function.cs
- CodeEventReferenceExpression.cs
- WebServiceErrorEvent.cs
- RSAPKCS1SignatureFormatter.cs
- HttpRequest.cs
- Utils.cs
- Section.cs
- panel.cs
- AccessibleObject.cs
- SubqueryRules.cs
- CacheChildrenQuery.cs
- ColumnBinding.cs
- CannotUnloadAppDomainException.cs
- WindowsSecurityTokenAuthenticator.cs
- X509SecurityToken.cs
- TokenBasedSetEnumerator.cs
- TimeSpanConverter.cs
- ObjectListSelectEventArgs.cs
- TokenizerHelper.cs
- TextTrailingCharacterEllipsis.cs
- FileIOPermission.cs
- HttpModulesInstallComponent.cs
- HttpCapabilitiesEvaluator.cs
- XmlWhitespace.cs