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
- CapabilitiesRule.cs
- Freezable.cs
- XmlCompatibilityReader.cs
- FormClosingEvent.cs
- XmlEnumAttribute.cs
- DependencyPropertyKey.cs
- DispatcherExceptionFilterEventArgs.cs
- MenuRendererStandards.cs
- ObjectViewListener.cs
- XPathParser.cs
- ProcessHost.cs
- XmlSchemaSimpleType.cs
- DomainConstraint.cs
- PhysicalFontFamily.cs
- TextBox.cs
- ObjectDataSourceFilteringEventArgs.cs
- TreeView.cs
- IsolatedStorage.cs
- Converter.cs
- MobileCategoryAttribute.cs
- BoolExpressionVisitors.cs
- DependencyPropertyValueSerializer.cs
- SerializableAttribute.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- GradientStopCollection.cs
- StylusPointProperty.cs
- ClientBuildManager.cs
- COM2ExtendedBrowsingHandler.cs
- AppearanceEditorPart.cs
- WsrmTraceRecord.cs
- ListViewAutomationPeer.cs
- X509SecurityToken.cs
- _FtpDataStream.cs
- EntityDataSourceContextCreatingEventArgs.cs
- DataGridColumnEventArgs.cs
- HwndHostAutomationPeer.cs
- mediapermission.cs
- ping.cs
- TraceLevelHelper.cs
- DataSourceXmlSerializationAttribute.cs
- GeometryGroup.cs
- DataGridViewUtilities.cs
- Canvas.cs
- SqlBuilder.cs
- __Filters.cs
- XmlNotation.cs
- ResourcePart.cs
- CompositeControl.cs
- XmlSchemaComplexContent.cs
- Pair.cs
- MailAddressParser.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- EventPrivateKey.cs
- SqlInternalConnectionTds.cs
- PerfProviderCollection.cs
- CodeTypeParameter.cs
- SqlUtils.cs
- ExtensionSimplifierMarkupObject.cs
- AddInStore.cs
- WindowsHyperlink.cs
- Transform.cs
- CriticalExceptions.cs
- ColumnMapVisitor.cs
- PageThemeCodeDomTreeGenerator.cs
- EditorZoneBase.cs
- TCEAdapterGenerator.cs
- RoleService.cs
- ExceptionTrace.cs
- FileFormatException.cs
- SqlDataSourceFilteringEventArgs.cs
- ExpressionWriter.cs
- ConnectionAcceptor.cs
- DetailsViewRow.cs
- DependencyProperty.cs
- BitConverter.cs
- AttributeCollection.cs
- RegexBoyerMoore.cs
- PropertyItem.cs
- SourceInterpreter.cs
- ReachPageContentSerializer.cs
- HttpListenerContext.cs
- DefaultValidator.cs
- PrimitiveRenderer.cs
- ConfigurationSectionGroup.cs
- Matrix3DConverter.cs
- TextModifier.cs
- Grammar.cs
- CollectionChangedEventManager.cs
- ServiceContractListItem.cs
- SiteMapSection.cs
- BinaryWriter.cs
- DllNotFoundException.cs
- ImageBrush.cs
- MsmqTransportSecurityElement.cs
- ValidatorCompatibilityHelper.cs
- BeginStoryboard.cs
- DocumentViewerBaseAutomationPeer.cs
- ExpressionEvaluator.cs
- BooleanKeyFrameCollection.cs
- DataGridViewButtonColumn.cs