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
- PasswordBoxAutomationPeer.cs
- ResourceKey.cs
- SmtpLoginAuthenticationModule.cs
- RemotingAttributes.cs
- FileDataSource.cs
- AlphaSortedEnumConverter.cs
- StrongNameKeyPair.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- MtomMessageEncodingBindingElement.cs
- ReadOnlyMetadataCollection.cs
- ListControlConvertEventArgs.cs
- ClientSection.cs
- TypeInitializationException.cs
- TraceLog.cs
- EventLogPermissionAttribute.cs
- TextAdaptor.cs
- SerializationIncompleteException.cs
- List.cs
- TileBrush.cs
- CharacterMetricsDictionary.cs
- LoginDesigner.cs
- ResourcesChangeInfo.cs
- TypedDataSetSchemaImporterExtension.cs
- TdsParserSessionPool.cs
- NativeMethods.cs
- SessionStateSection.cs
- DataTablePropertyDescriptor.cs
- CompatibleComparer.cs
- WmpBitmapDecoder.cs
- BitmapEffectDrawingContextState.cs
- OrderingExpression.cs
- NotCondition.cs
- EdmError.cs
- FormatConvertedBitmap.cs
- AutomationPattern.cs
- SqlCacheDependencyDatabase.cs
- GeneralTransform2DTo3DTo2D.cs
- WindowsPrincipal.cs
- TileBrush.cs
- SessionStateUtil.cs
- Object.cs
- BezierSegment.cs
- TabControl.cs
- PageEventArgs.cs
- FixedTextPointer.cs
- WebPartMinimizeVerb.cs
- IPCCacheManager.cs
- CallTemplateAction.cs
- MetadataWorkspace.cs
- ObjectQueryProvider.cs
- ParameterToken.cs
- StringToken.cs
- SQLMoneyStorage.cs
- DocumentGridPage.cs
- TreeNodeStyleCollectionEditor.cs
- DelegatedStream.cs
- CreateDataSourceDialog.cs
- DelimitedListTraceListener.cs
- RecognizerBase.cs
- ResetableIterator.cs
- SettingsPropertyValueCollection.cs
- TreeNodeStyleCollection.cs
- TimeSpanConverter.cs
- StyleSheetDesigner.cs
- ToolboxDataAttribute.cs
- HtmlInputReset.cs
- HttpContext.cs
- ObjectSecurity.cs
- HttpConfigurationSystem.cs
- SqlProviderUtilities.cs
- CalloutQueueItem.cs
- ThreadStateException.cs
- ErrorHandlingAcceptor.cs
- MsmqIntegrationMessageProperty.cs
- AttributeUsageAttribute.cs
- KeyPullup.cs
- UnSafeCharBuffer.cs
- QilScopedVisitor.cs
- ValueSerializer.cs
- AttributeParameterInfo.cs
- SystemColorTracker.cs
- StringReader.cs
- RepeatBehaviorConverter.cs
- ResourceAttributes.cs
- MembershipSection.cs
- EncodingFallbackAwareXmlTextWriter.cs
- StaticDataManager.cs
- OutputScopeManager.cs
- RuntimeResourceSet.cs
- ReflectionTypeLoadException.cs
- AnnotationComponentManager.cs
- AppLevelCompilationSectionCache.cs
- CacheChildrenQuery.cs
- XmlAttributeProperties.cs
- DeploymentSection.cs
- BulletedListDesigner.cs
- ApplicationManager.cs
- BrowserDefinitionCollection.cs
- TextStore.cs
- ChtmlTextWriter.cs