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
- AuthenticationManager.cs
- ToolbarAUtomationPeer.cs
- DataGridViewColumnHeaderCell.cs
- MarkedHighlightComponent.cs
- BrushValueSerializer.cs
- LinkConverter.cs
- Speller.cs
- KeyedHashAlgorithm.cs
- SqlServer2KCompatibilityAnnotation.cs
- XmlAttributes.cs
- Profiler.cs
- InputMethodStateTypeInfo.cs
- UnsafeNativeMethods.cs
- ToolStripLocationCancelEventArgs.cs
- CultureInfo.cs
- Mappings.cs
- EdmItemCollection.cs
- ActivationServices.cs
- DataSourceControl.cs
- ConnectionConsumerAttribute.cs
- WindowsPrincipal.cs
- InkCanvasSelection.cs
- AddInControllerImpl.cs
- XmlDesigner.cs
- AgileSafeNativeMemoryHandle.cs
- Image.cs
- SolidBrush.cs
- DynamicRenderer.cs
- TextBounds.cs
- UnsafeNativeMethods.cs
- FormViewPagerRow.cs
- WebPageTraceListener.cs
- MobileContainerDesigner.cs
- ManipulationPivot.cs
- FunctionCommandText.cs
- Validator.cs
- CodeArrayIndexerExpression.cs
- SqlMethodTransformer.cs
- Decorator.cs
- SafeCoTaskMem.cs
- WindowsRegion.cs
- HtmlElementEventArgs.cs
- DataGridViewColumn.cs
- TextStore.cs
- SystemIPGlobalProperties.cs
- NullableBoolConverter.cs
- TimelineClockCollection.cs
- AsymmetricSecurityBindingElement.cs
- LoginCancelEventArgs.cs
- pingexception.cs
- DataSourceHelper.cs
- WizardPanel.cs
- SqlStatistics.cs
- Rect3DValueSerializer.cs
- ProfileSection.cs
- ButtonRenderer.cs
- SerialStream.cs
- BamlRecordReader.cs
- ResXResourceWriter.cs
- CatalogPartDesigner.cs
- PenLineJoinValidation.cs
- UnionQueryOperator.cs
- XmlSerializer.cs
- WorkflowElementDialog.cs
- BuildResult.cs
- WindowsFont.cs
- SelectionEditor.cs
- WindowsButton.cs
- PointAnimationBase.cs
- _CookieModule.cs
- DrawingCollection.cs
- HandleInitializationContext.cs
- GAC.cs
- DbProviderFactories.cs
- DataMisalignedException.cs
- ScrollableControl.cs
- ByteConverter.cs
- PagePropertiesChangingEventArgs.cs
- SessionParameter.cs
- ExpressionBuilder.cs
- System.Data_BID.cs
- SymDocumentType.cs
- XmlSchemaRedefine.cs
- TripleDES.cs
- ServiceProviders.cs
- MessageBuilder.cs
- SelectionItemPattern.cs
- Transactions.cs
- FastPropertyAccessor.cs
- BuilderPropertyEntry.cs
- ScrollableControl.cs
- SessionStateSection.cs
- MSAAWinEventWrap.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- EventProperty.cs
- SchemaConstraints.cs
- RbTree.cs
- XamlPointCollectionSerializer.cs
- SerializationInfo.cs
- GPStream.cs