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
- TypeKeyValue.cs
- Regex.cs
- SemanticAnalyzer.cs
- Number.cs
- QueryOptionExpression.cs
- StrokeFIndices.cs
- EventLogEntryCollection.cs
- KeyEventArgs.cs
- GeometryConverter.cs
- BuildProvider.cs
- ObjectDataProvider.cs
- DESCryptoServiceProvider.cs
- EndPoint.cs
- FlagsAttribute.cs
- XhtmlTextWriter.cs
- odbcmetadatacolumnnames.cs
- DynamicResourceExtension.cs
- CombinedTcpChannel.cs
- RoleService.cs
- CrossSiteScriptingValidation.cs
- SiteMembershipCondition.cs
- ISFTagAndGuidCache.cs
- DockAndAnchorLayout.cs
- PlainXmlSerializer.cs
- GZipObjectSerializer.cs
- VisualBrush.cs
- ToolStripArrowRenderEventArgs.cs
- SpeechAudioFormatInfo.cs
- XmlDocumentType.cs
- MetafileHeaderEmf.cs
- GridView.cs
- Geometry3D.cs
- XmlStringTable.cs
- ApplicationActivator.cs
- FormsAuthenticationTicket.cs
- RotateTransform.cs
- EventlogProvider.cs
- DefaultValueAttribute.cs
- FontStyles.cs
- CompositeActivityMarkupSerializer.cs
- DataGridViewLayoutData.cs
- CodeSpit.cs
- SiteMapNodeCollection.cs
- Rotation3D.cs
- TemplateParser.cs
- ToolStripDesignerUtils.cs
- EncoderParameter.cs
- TextAction.cs
- ThreadSafeList.cs
- iisPickupDirectory.cs
- ReferentialConstraint.cs
- SingletonConnectionReader.cs
- Assembly.cs
- SyntaxCheck.cs
- CompositeFontInfo.cs
- DynamicHyperLink.cs
- DeploymentSection.cs
- HttpServerUtilityWrapper.cs
- SpnegoTokenAuthenticator.cs
- FixedSOMPageConstructor.cs
- Bold.cs
- WebPartConnectionsConfigureVerb.cs
- SoapSchemaExporter.cs
- SQLByteStorage.cs
- OdbcEnvironment.cs
- CachedPathData.cs
- ParallelActivityDesigner.cs
- IDReferencePropertyAttribute.cs
- WaitHandleCannotBeOpenedException.cs
- XmlDataSourceNodeDescriptor.cs
- UserPreferenceChangedEventArgs.cs
- SecureEnvironment.cs
- BindingContext.cs
- SiteMapDataSource.cs
- SafeNativeMethods.cs
- XmlSchemaComplexContentExtension.cs
- SoapInteropTypes.cs
- HijriCalendar.cs
- AddInEnvironment.cs
- ToolStripCollectionEditor.cs
- EditorPartChrome.cs
- SessionStateContainer.cs
- ObjectDataSourceView.cs
- PageEventArgs.cs
- DynamicMethod.cs
- ColorTransform.cs
- BindingMAnagerBase.cs
- CustomAttributeBuilder.cs
- SmtpDigestAuthenticationModule.cs
- ApplicationDirectoryMembershipCondition.cs
- ContentFileHelper.cs
- DataGridViewAutoSizeModeEventArgs.cs
- Run.cs
- SqlVersion.cs
- CompilerTypeWithParams.cs
- RegexCapture.cs
- HttpCacheVary.cs
- OptimizedTemplateContentHelper.cs
- SwitchLevelAttribute.cs
- DeferredBinaryDeserializerExtension.cs