Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Runtime / Pool.cs / 1305376 / Pool.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Runtime { using System; using System.Runtime; // Pooldefined below is a LIFO pool of Pool.IClearable objects. // It is strongly typed to make the Acquire/Release methods more user // friendly. To use this pool, subclass it with a concrete type and // override the CreateNew method. Typically, the type of T will // have a default ctor and will use an Initialize(...) method in order // to configure it for use. // NOTE: CreateNew is required because T : new() requires that the default // ctor is public. We did not want to put public ctors on some of our // pooled resources (like NativeActivityContext). abstract class Pool { const int DefaultPoolSize = 10; T[] items; int count; int poolSize; public Pool() : this(DefaultPoolSize) { } public Pool(int poolSize) { this.items = new T[poolSize]; this.poolSize = poolSize; } public T Acquire() { if (this.count > 0) { this.count--; T item = this.items[this.count]; return item; } else { return CreateNew(); } } protected abstract T CreateNew(); public void Release(T item) { if (this.count < this.poolSize) { this.items[this.count] = item; this.count++; } } } } // 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
- Win32Native.cs
- RoleManagerSection.cs
- WindowsScroll.cs
- UnlockInstanceAsyncResult.cs
- BuiltInExpr.cs
- WizardDesigner.cs
- RowVisual.cs
- AttachedAnnotationChangedEventArgs.cs
- EncoderExceptionFallback.cs
- InkCanvas.cs
- FontFaceLayoutInfo.cs
- ComplexObject.cs
- OverrideMode.cs
- SoapAttributes.cs
- DefaultDiscoveryService.cs
- RuleSetBrowserDialog.cs
- Baml2006KnownTypes.cs
- CompilerHelpers.cs
- LayoutExceptionEventArgs.cs
- CachedFontFace.cs
- Error.cs
- sqlstateclientmanager.cs
- WindowsFormsLinkLabel.cs
- SystemColorTracker.cs
- BigIntegerStorage.cs
- SelectionRangeConverter.cs
- ExtensionSimplifierMarkupObject.cs
- StorageEntityContainerMapping.cs
- ToolboxItemLoader.cs
- Converter.cs
- CommandDevice.cs
- DataTemplateKey.cs
- DefaultSettingsSection.cs
- ValidateNames.cs
- TextComposition.cs
- Baml6Assembly.cs
- XmlEventCache.cs
- PropertyGridEditorPart.cs
- EmbeddedMailObject.cs
- BitmapEffect.cs
- HttpWriter.cs
- __FastResourceComparer.cs
- TypeListConverter.cs
- ReferenceEqualityComparer.cs
- MSG.cs
- AssemblyNameProxy.cs
- EntryWrittenEventArgs.cs
- ShaderRenderModeValidation.cs
- BaseTemplateParser.cs
- CallbackHandler.cs
- SafeNativeMethods.cs
- NamedPipeAppDomainProtocolHandler.cs
- mactripleDES.cs
- DbDataAdapter.cs
- StrokeDescriptor.cs
- ParseChildrenAsPropertiesAttribute.cs
- AxisAngleRotation3D.cs
- EventWaitHandleSecurity.cs
- PrintPageEvent.cs
- ContentElement.cs
- KerberosTicketHashIdentifierClause.cs
- RequestQueryParser.cs
- ReferentialConstraintRoleElement.cs
- RijndaelManaged.cs
- ResourceWriter.cs
- WindowsFormsSynchronizationContext.cs
- TreeViewEvent.cs
- UnsignedPublishLicense.cs
- GeometryCombineModeValidation.cs
- CommonEndpointBehaviorElement.cs
- arc.cs
- TypeBrowser.xaml.cs
- LabelExpression.cs
- SvcMapFile.cs
- SrgsToken.cs
- InkCanvasFeedbackAdorner.cs
- TextDecoration.cs
- QueryResponse.cs
- DesignerWidgets.cs
- RefreshResponseInfo.cs
- FrameworkElement.cs
- EntityDataSourceWrapperCollection.cs
- DynamicValueConverter.cs
- SingleObjectCollection.cs
- DrawItemEvent.cs
- DataBindEngine.cs
- EventsTab.cs
- TransformDescriptor.cs
- TemplateParser.cs
- XPathMultyIterator.cs
- _HelperAsyncResults.cs
- SettingsBase.cs
- ByteStreamMessage.cs
- ConditionalAttribute.cs
- InternalConfigConfigurationFactory.cs
- ExpressionBinding.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- SqlProvider.cs
- ResourceCategoryAttribute.cs
- Menu.cs