Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media / SafeMILHandleMemoryPressure.cs / 1407647 / SafeMILHandleMemoryPressure.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // Tracks the amount of native memory used by SafeMILHandle objects. //--------------------------------------------------------------------------- using System; using System.Security; using MS.Internal; using System.Threading; namespace System.Windows.Media { internal class SafeMILHandleMemoryPressure { ////// Critical: This code calls into AddMemoryPressure which has a link demand. /// [SecurityCritical] internal SafeMILHandleMemoryPressure(long gcPressure) { _gcPressure = gcPressure; _refCount = 0; if (_gcPressure > SMALL_BITMAP_MEM) { MemoryPressure.Add(_gcPressure); } else { GC.AddMemoryPressure(_gcPressure); } } internal void AddRef() { Interlocked.Increment(ref _refCount); } ////// Critical: This code calls into RemoveMemoryPressure which has a link demand. /// [SecurityCritical] internal void Release() { if (Interlocked.Decrement(ref _refCount) == 0) { if (_gcPressure > SMALL_BITMAP_MEM) { MemoryPressure.Remove(_gcPressure); } else { GC.RemoveMemoryPressure(_gcPressure); } _gcPressure = 0; } } // Estimated size in bytes of the unmanaged memory private long _gcPressure; // // SafeMILHandleMemoryPressure does its own ref counting in managed code, because the // associated memory pressure should be removed when there are no more managed // references to the unmanaged resource. There can still be references to it from // unmanaged code elsewhere, but that should not prevent the memory pressure from being // released. // private int _refCount; // // The memory usage for a "small" bitmap // // Small bitmaps will be handled by GC.AddMemoryPressure() rather than WPF's own // MemoryPressure algorithm. GC's algorithm is less aggressive than WPF's, and will // result in fewer expensive GC.Collect(2) operations. // // For now, a small bitmap is 32x32 or less. It's at 4 bytes per pixel, and the *2 is // to account for the doubled estimate in // BitmapSourceMILSafeHandle.ComputeEstimatedSize(). // private const long SMALL_BITMAP_MEM = 32 * 32 * 4 * 2; } } // 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
- MILUtilities.cs
- CompleteWizardStep.cs
- ApplicationServiceHelper.cs
- EntityContainerEmitter.cs
- ComboBoxItem.cs
- AnnotationHighlightLayer.cs
- WriteableBitmap.cs
- ProtectedConfigurationSection.cs
- ExtensionWindow.cs
- SymmetricAlgorithm.cs
- RSAOAEPKeyExchangeFormatter.cs
- HtmlFormWrapper.cs
- FrameworkTextComposition.cs
- SkinBuilder.cs
- ArraySet.cs
- DesignColumnCollection.cs
- InputScopeNameConverter.cs
- MemberInfoSerializationHolder.cs
- BamlResourceDeserializer.cs
- autovalidator.cs
- ToolStripDropDownItemDesigner.cs
- PlanCompilerUtil.cs
- PeerApplication.cs
- XamlFigureLengthSerializer.cs
- Application.cs
- MediaElement.cs
- ReliabilityContractAttribute.cs
- WeakEventManager.cs
- ObjectDataSourceMethodEditor.cs
- KeyEvent.cs
- MetadataArtifactLoaderCompositeResource.cs
- TextPointer.cs
- AbsoluteQuery.cs
- CategoryNameCollection.cs
- RawStylusSystemGestureInputReport.cs
- ConfigXmlCDataSection.cs
- ClientOptions.cs
- ConstraintStruct.cs
- PopupRootAutomationPeer.cs
- DeviceContext2.cs
- HwndProxyElementProvider.cs
- ZipIOFileItemStream.cs
- FunctionDescription.cs
- UIElement3D.cs
- PersonalizableAttribute.cs
- RenderData.cs
- StylusPointPropertyId.cs
- GuidelineCollection.cs
- SqlError.cs
- ReplyChannel.cs
- SubtreeProcessor.cs
- TableItemProviderWrapper.cs
- RequestContext.cs
- ImportContext.cs
- SpellerError.cs
- TemplateNameScope.cs
- SafeNativeMethods.cs
- ISAPIRuntime.cs
- LoadRetryConstantStrategy.cs
- RecordManager.cs
- _ConnectionGroup.cs
- CreateSequenceResponse.cs
- SmtpMail.cs
- Light.cs
- XmlNavigatorFilter.cs
- InputScopeManager.cs
- XmlStringTable.cs
- XmlNotation.cs
- CqlLexer.cs
- ActivityBuilder.cs
- ListViewItemEventArgs.cs
- BamlLocalizationDictionary.cs
- WorkflowRuntimeServicesBehavior.cs
- EnlistmentState.cs
- TextFormatterImp.cs
- HttpModuleActionCollection.cs
- PanelStyle.cs
- ObjectContextServiceProvider.cs
- InputScopeConverter.cs
- FeatureSupport.cs
- HtmlAnchor.cs
- SectionRecord.cs
- ReliabilityContractAttribute.cs
- AmbientValueAttribute.cs
- SHA384.cs
- DependencyPropertyDescriptor.cs
- PathFigure.cs
- Point3DKeyFrameCollection.cs
- sqlmetadatafactory.cs
- Debug.cs
- DynamicScriptObject.cs
- HttpCookie.cs
- BinaryConverter.cs
- ParserContext.cs
- SqlDataSourceCommandEventArgs.cs
- DataGrid.cs
- DetailsViewPagerRow.cs
- MultiBinding.cs
- ControlParameter.cs
- StringDictionary.cs