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
- DataContractFormatAttribute.cs
- Tuple.cs
- GuidConverter.cs
- ViewGenResults.cs
- EqualityArray.cs
- SectionVisual.cs
- HandlerWithFactory.cs
- AmbiguousMatchException.cs
- WmlPhoneCallAdapter.cs
- MimeFormImporter.cs
- UrlMappingsModule.cs
- RelationshipNavigation.cs
- DiscriminatorMap.cs
- PageAsyncTask.cs
- ToolStripItemImageRenderEventArgs.cs
- ClientFactory.cs
- FakeModelItemImpl.cs
- DataServiceQueryOfT.cs
- DescendantOverDescendantQuery.cs
- BevelBitmapEffect.cs
- SelectionRange.cs
- DataGridViewCellConverter.cs
- VectorCollectionConverter.cs
- embossbitmapeffect.cs
- ResetableIterator.cs
- Pen.cs
- ExtentJoinTreeNode.cs
- DbProviderFactory.cs
- DropDownList.cs
- SelectionGlyph.cs
- ExtenderProvidedPropertyAttribute.cs
- IsolatedStorageFileStream.cs
- LinkedResource.cs
- DataServices.cs
- Timer.cs
- FunctionDescription.cs
- CompensatableTransactionScopeActivity.cs
- ByteAnimationBase.cs
- UpdateTracker.cs
- OdbcCommandBuilder.cs
- XmlNamespaceDeclarationsAttribute.cs
- DataServiceQueryContinuation.cs
- DataGridComboBoxColumn.cs
- SID.cs
- SiteMapNodeCollection.cs
- LineUtil.cs
- Literal.cs
- RawStylusActions.cs
- ServiceMemoryGates.cs
- PublishLicense.cs
- DetailsViewRow.cs
- DockPatternIdentifiers.cs
- ConfigurationSchemaErrors.cs
- Floater.cs
- DrawingGroup.cs
- ServicePoint.cs
- XhtmlBasicValidationSummaryAdapter.cs
- Symbol.cs
- ReachDocumentReferenceCollectionSerializer.cs
- TextBoxBase.cs
- HtmlShimManager.cs
- EdmScalarPropertyAttribute.cs
- TableLayoutPanelCellPosition.cs
- QueryExpr.cs
- SizeConverter.cs
- Token.cs
- StrokeNode.cs
- WsiProfilesElementCollection.cs
- XmlSchemaElement.cs
- CodePageUtils.cs
- MultiByteCodec.cs
- NativeMethods.cs
- WebPartActionVerb.cs
- HttpProfileGroupBase.cs
- WebPartCollection.cs
- FormatterServices.cs
- SerializationEventsCache.cs
- ProcessModule.cs
- ProfileGroupSettings.cs
- Cursor.cs
- FilteredAttributeCollection.cs
- OleDbWrapper.cs
- DocumentCollection.cs
- WebPartEditorCancelVerb.cs
- PageBreakRecord.cs
- ConfigXmlText.cs
- SqlBinder.cs
- ThemeDirectoryCompiler.cs
- EmptyCollection.cs
- LayoutTable.cs
- UrlAuthFailedErrorFormatter.cs
- WebHttpBindingCollectionElement.cs
- SchemaNames.cs
- WebEventCodes.cs
- EdmSchemaError.cs
- SortedSetDebugView.cs
- GenericEnumerator.cs
- XmlNodeList.cs
- FormViewUpdateEventArgs.cs
- ResourceContainer.cs