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
- MultiTargetingUtil.cs
- _SpnDictionary.cs
- EventSchemaTraceListener.cs
- StatusBarAutomationPeer.cs
- ProvidersHelper.cs
- WebPermission.cs
- SqlParameterCollection.cs
- EntityConnectionStringBuilderItem.cs
- DrawingGroupDrawingContext.cs
- PointCollection.cs
- SystemInfo.cs
- ModelTypeConverter.cs
- BlockCollection.cs
- DescendantOverDescendantQuery.cs
- TypeResolvingOptionsAttribute.cs
- EndpointInstanceProvider.cs
- SignedInfo.cs
- DrawingGroup.cs
- XmlSchemaFacet.cs
- CountAggregationOperator.cs
- TextSyndicationContent.cs
- TraceHandlerErrorFormatter.cs
- ToolZone.cs
- DynamicDataManager.cs
- SqlUtil.cs
- AuthorizationRuleCollection.cs
- DefaultValueTypeConverter.cs
- ClientApiGenerator.cs
- SingleAnimationBase.cs
- DesignerDataTable.cs
- EventLogHandle.cs
- WCFBuildProvider.cs
- UnionExpr.cs
- SelectingProviderEventArgs.cs
- PolygonHotSpot.cs
- Pair.cs
- ListViewGroup.cs
- CompilerInfo.cs
- XmlSchema.cs
- SubclassTypeValidatorAttribute.cs
- TypeElement.cs
- EnvironmentPermission.cs
- UIAgentMonitor.cs
- OverrideMode.cs
- InputBindingCollection.cs
- SortQuery.cs
- DragStartedEventArgs.cs
- ScrollBarAutomationPeer.cs
- SiteMapProvider.cs
- Image.cs
- CheckBoxStandardAdapter.cs
- Int32CAMarshaler.cs
- PageCatalogPart.cs
- GlyphingCache.cs
- sqlser.cs
- Substitution.cs
- KnownBoxes.cs
- TripleDES.cs
- OdbcEnvironmentHandle.cs
- DataPagerField.cs
- MetaModel.cs
- HttpUnhandledOperationInvoker.cs
- BitmapEffectInputData.cs
- StrongNameIdentityPermission.cs
- ParentUndoUnit.cs
- AddingNewEventArgs.cs
- NativeMethods.cs
- GlyphRunDrawing.cs
- Effect.cs
- listitem.cs
- SqlTypeSystemProvider.cs
- SqlConnectionHelper.cs
- RegionInfo.cs
- ColorTranslator.cs
- XmlSchemaFacet.cs
- NumericUpDownAccelerationCollection.cs
- ContractMapping.cs
- ServerProtocol.cs
- DataGridViewTextBoxColumn.cs
- TreeNodeSelectionProcessor.cs
- ContainerFilterService.cs
- RootProfilePropertySettingsCollection.cs
- DataPagerField.cs
- OrderByBuilder.cs
- ListComponentEditorPage.cs
- PublishLicense.cs
- SettingsPropertyIsReadOnlyException.cs
- EventWaitHandleSecurity.cs
- PaintEvent.cs
- ExceptionUtil.cs
- DataGridViewToolTip.cs
- DataControlFieldsEditor.cs
- PageBreakRecord.cs
- VBIdentifierDesigner.xaml.cs
- DSACryptoServiceProvider.cs
- CodeCastExpression.cs
- DefaultCommandExtensionCallback.cs
- ImageFormatConverter.cs
- filewebresponse.cs
- Substitution.cs