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
- ObjectConverter.cs
- AssemblyName.cs
- BitSet.cs
- XmlSchemaSequence.cs
- BitmapEffectInput.cs
- Shape.cs
- ContentType.cs
- PipelineComponent.cs
- SelectionEditingBehavior.cs
- ItemMap.cs
- DataSourceXmlElementAttribute.cs
- HttpStreams.cs
- FormViewDesigner.cs
- SchemaElementDecl.cs
- HiddenFieldDesigner.cs
- RepeatInfo.cs
- CommandConverter.cs
- TextViewDesigner.cs
- NoResizeHandleGlyph.cs
- SwitchElementsCollection.cs
- CalculatedColumn.cs
- ColumnClickEvent.cs
- HelpProvider.cs
- AsymmetricSignatureFormatter.cs
- SettingsPropertyValue.cs
- VScrollProperties.cs
- DBConnectionString.cs
- ColorBlend.cs
- ToolStripContentPanelRenderEventArgs.cs
- FacetValueContainer.cs
- MembershipUser.cs
- EventProviderWriter.cs
- BaseParaClient.cs
- SqlInfoMessageEvent.cs
- DetailsViewUpdatedEventArgs.cs
- ModifierKeysConverter.cs
- COM2ExtendedBrowsingHandler.cs
- FilterUserControlBase.cs
- FontCacheLogic.cs
- Thickness.cs
- ServiceBehaviorElement.cs
- DiagnosticTraceSource.cs
- AttachmentCollection.cs
- RijndaelCryptoServiceProvider.cs
- WebPermission.cs
- CachedPathData.cs
- Marshal.cs
- HelpEvent.cs
- RouteValueDictionary.cs
- SizeAnimation.cs
- CustomErrorCollection.cs
- SafeLibraryHandle.cs
- RequestCachePolicyConverter.cs
- MethodImplAttribute.cs
- DbConnectionPoolIdentity.cs
- EndpointDiscoveryMetadataCD1.cs
- CompoundFileStorageReference.cs
- odbcmetadatacolumnnames.cs
- BinaryMessageEncoder.cs
- StylusDownEventArgs.cs
- SmtpClient.cs
- SimpleModelProvider.cs
- LeftCellWrapper.cs
- TextLineResult.cs
- WorkflowEventArgs.cs
- JapaneseCalendar.cs
- SQLMembershipProvider.cs
- VirtualPathProvider.cs
- GatewayDefinition.cs
- DLinqTableProvider.cs
- ImageMapEventArgs.cs
- DesignRelation.cs
- ReferencedAssembly.cs
- TemplatedMailWebEventProvider.cs
- AudioFileOut.cs
- EventProviderWriter.cs
- SiblingIterators.cs
- Clipboard.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- ObjectReaderCompiler.cs
- PeerToPeerException.cs
- PropertyValueChangedEvent.cs
- WindowsGraphics.cs
- LastQueryOperator.cs
- DbMetaDataColumnNames.cs
- SetState.cs
- HelloOperationCD1AsyncResult.cs
- DockProviderWrapper.cs
- securitycriticaldataClass.cs
- ToolboxService.cs
- AccessibleObject.cs
- CustomErrorsSectionWrapper.cs
- SendKeys.cs
- ObsoleteAttribute.cs
- SHA256.cs
- ImageAnimator.cs
- DictionarySectionHandler.cs
- XmlSchemaElement.cs
- CodeCompileUnit.cs
- UndoEngine.cs