Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Linq / Parallel / Utils / GrowingArray.cs / 1305376 / GrowingArray.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // GrowingArray.cs // //[....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// A growing array. Unlike List{T}, it makes the internal array available to its user. /// ///internal class GrowingArray { T[] m_array; int m_count; const int DEFAULT_ARRAY_SIZE = 1024; internal GrowingArray() { m_array = new T[DEFAULT_ARRAY_SIZE]; m_count = 0; } //---------------------------------------------------------------------------------------- // Returns the internal array representing the list. Note that the array may be larger // than necessary to hold all elements in the list. // internal T[] InternalArray { get { return m_array; } } internal int Count { get { return m_count; } } internal void Add(T element) { if (m_count >= m_array.Length) { GrowArray(2 * m_array.Length); } m_array[m_count++] = element; } private void GrowArray(int newSize) { Contract.Assert(newSize > m_array.Length); T[] array2 = new T[newSize]; m_array.CopyTo(array2, 0); m_array = array2; } internal void CopyFrom(T[] otherArray, int otherCount) { // Ensure there is just enough room for both. if (m_count + otherCount > m_array.Length) { GrowArray(m_count + otherCount); } // And now just blit the keys directly. Array.Copy(otherArray, 0, m_array, m_count, otherCount); m_count += otherCount; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // GrowingArray.cs // // [....] // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Diagnostics.Contracts; namespace System.Linq.Parallel { ////// A growing array. Unlike List{T}, it makes the internal array available to its user. /// ///internal class GrowingArray { T[] m_array; int m_count; const int DEFAULT_ARRAY_SIZE = 1024; internal GrowingArray() { m_array = new T[DEFAULT_ARRAY_SIZE]; m_count = 0; } //---------------------------------------------------------------------------------------- // Returns the internal array representing the list. Note that the array may be larger // than necessary to hold all elements in the list. // internal T[] InternalArray { get { return m_array; } } internal int Count { get { return m_count; } } internal void Add(T element) { if (m_count >= m_array.Length) { GrowArray(2 * m_array.Length); } m_array[m_count++] = element; } private void GrowArray(int newSize) { Contract.Assert(newSize > m_array.Length); T[] array2 = new T[newSize]; m_array.CopyTo(array2, 0); m_array = array2; } internal void CopyFrom(T[] otherArray, int otherCount) { // Ensure there is just enough room for both. if (m_count + otherCount > m_array.Length) { GrowArray(m_count + otherCount); } // And now just blit the keys directly. Array.Copy(otherArray, 0, m_array, m_count, otherCount); m_count += otherCount; } } } // 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
- Triplet.cs
- ConstructorBuilder.cs
- UIPropertyMetadata.cs
- EntityDataSourceEntitySetNameItem.cs
- XmlSchemaAppInfo.cs
- WsatServiceCertificate.cs
- ReflectionPermission.cs
- RuleEngine.cs
- DefaultClaimSet.cs
- webclient.cs
- XhtmlBasicPanelAdapter.cs
- FontFamilyConverter.cs
- SelectQueryOperator.cs
- QueryNode.cs
- DataControlLinkButton.cs
- ExtensionFile.cs
- _AutoWebProxyScriptWrapper.cs
- FontStretches.cs
- ListView.cs
- FontCacheLogic.cs
- PropertyMetadata.cs
- Transform.cs
- CodeSubDirectory.cs
- ApplicationDirectory.cs
- SelectionProcessor.cs
- BigIntegerStorage.cs
- MatrixAnimationUsingPath.cs
- MetafileHeader.cs
- ErrorProvider.cs
- CallSiteBinder.cs
- XmlSchemaAll.cs
- CodeParameterDeclarationExpressionCollection.cs
- HttpListener.cs
- WebServiceEndpoint.cs
- TypefaceMap.cs
- Localizer.cs
- RsaElement.cs
- dataprotectionpermissionattribute.cs
- ToolCreatedEventArgs.cs
- DataGridColumnHeader.cs
- TextEditorTables.cs
- RequestUriProcessor.cs
- XsdCachingReader.cs
- RouteItem.cs
- ColorContext.cs
- ConnectionManagementElementCollection.cs
- StdRegProviderWrapper.cs
- OpenFileDialog.cs
- DbInsertCommandTree.cs
- PostBackOptions.cs
- X509Extension.cs
- TextTreeObjectNode.cs
- X509Chain.cs
- XmlDataSource.cs
- ISAPIApplicationHost.cs
- MoveSizeWinEventHandler.cs
- WebPartUserCapability.cs
- HandledMouseEvent.cs
- AccessDataSource.cs
- BlurEffect.cs
- SerializerProvider.cs
- ContentControl.cs
- RtfToXamlReader.cs
- WebRequestModulesSection.cs
- AlternateViewCollection.cs
- XmlNotation.cs
- EndPoint.cs
- ProxyAttribute.cs
- ProgressBarHighlightConverter.cs
- BaseParser.cs
- XpsDocumentEvent.cs
- ZipIOExtraFieldPaddingElement.cs
- TableRowGroup.cs
- Triangle.cs
- ScrollableControl.cs
- CompilerErrorCollection.cs
- AutoCompleteStringCollection.cs
- BrushMappingModeValidation.cs
- SystemIcons.cs
- X509Certificate.cs
- SchemaImporterExtensionElementCollection.cs
- WindowsStatic.cs
- BamlResourceDeserializer.cs
- AutoGeneratedField.cs
- BufferAllocator.cs
- TypeLibConverter.cs
- WindowsSolidBrush.cs
- PrintDialogException.cs
- EntryPointNotFoundException.cs
- TypographyProperties.cs
- SQLUtility.cs
- RuleValidation.cs
- BuildProviderAppliesToAttribute.cs
- SystemResourceHost.cs
- SiteMapHierarchicalDataSourceView.cs
- AppliesToBehaviorDecisionTable.cs
- Matrix3D.cs
- SecurityHeaderLayout.cs
- BaseCollection.cs
- Action.cs