Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / 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
- PointConverter.cs
- DSACryptoServiceProvider.cs
- Update.cs
- WebServiceTypeData.cs
- SkipStoryboardToFill.cs
- DispatcherHookEventArgs.cs
- TextServicesContext.cs
- OdbcEnvironmentHandle.cs
- HyperLink.cs
- XmlNodeChangedEventArgs.cs
- FrugalMap.cs
- EntityKey.cs
- AmbientValueAttribute.cs
- WsatRegistrationHeader.cs
- TemplateContent.cs
- handlecollector.cs
- XPathScanner.cs
- WizardStepBase.cs
- SelectionWordBreaker.cs
- AnnotationHelper.cs
- PrePrepareMethodAttribute.cs
- sqlcontext.cs
- CaseKeyBox.ViewModel.cs
- EventRouteFactory.cs
- WizardForm.cs
- FormsAuthentication.cs
- TextContainerHelper.cs
- EmptyCollection.cs
- CornerRadiusConverter.cs
- UnicastIPAddressInformationCollection.cs
- DiagnosticsConfigurationHandler.cs
- ViewValidator.cs
- DefaultObjectMappingItemCollection.cs
- DataBoundLiteralControl.cs
- VisualTarget.cs
- CalendarTable.cs
- Mapping.cs
- XmlWhitespace.cs
- QuaternionConverter.cs
- InternalConfigRoot.cs
- TagPrefixInfo.cs
- StatusBarPanel.cs
- DesignerActionKeyboardBehavior.cs
- ReaderWriterLock.cs
- FlowDocumentPage.cs
- Underline.cs
- MethodExpr.cs
- IssuanceLicense.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- XmlSchemaResource.cs
- FileDialogCustomPlacesCollection.cs
- ScrollEventArgs.cs
- DataGridColumnHeaderItemAutomationPeer.cs
- CallTemplateAction.cs
- PEFileEvidenceFactory.cs
- ProfileSettings.cs
- Thumb.cs
- ContainerUIElement3D.cs
- SafeNativeMethodsOther.cs
- BooleanStorage.cs
- XmlSchemaInfo.cs
- CodeIdentifiers.cs
- EpmTargetTree.cs
- SqlMethods.cs
- ProcessManager.cs
- MultiSelectRootGridEntry.cs
- ConnectionPoint.cs
- DbConnectionPoolGroupProviderInfo.cs
- TextDpi.cs
- ITreeGenerator.cs
- LayoutDump.cs
- ServicePoint.cs
- StorageAssociationTypeMapping.cs
- SoapExtensionTypeElement.cs
- AudioFormatConverter.cs
- BooleanStorage.cs
- CultureInfoConverter.cs
- Int32CAMarshaler.cs
- XPathAxisIterator.cs
- MulticastIPAddressInformationCollection.cs
- HttpHandlerActionCollection.cs
- MessageBodyDescription.cs
- FormViewUpdatedEventArgs.cs
- SQLGuidStorage.cs
- EntityDataSourceContextCreatingEventArgs.cs
- KeyboardDevice.cs
- RNGCryptoServiceProvider.cs
- SQLDateTimeStorage.cs
- DataList.cs
- MediaElement.cs
- ApplicationServiceHelper.cs
- WriteTimeStream.cs
- SchemaElement.cs
- StatementContext.cs
- IdentityModelDictionary.cs
- _NegotiateClient.cs
- WorkflowInstanceProxy.cs
- SynchronizingStream.cs
- UIElement3DAutomationPeer.cs
- SessionPageStatePersister.cs