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
- BStrWrapper.cs
- securitycriticaldataClass.cs
- DictionaryEditChange.cs
- DynamicActionMessageFilter.cs
- ConfigurationElementProperty.cs
- StringUtil.cs
- SmiGettersStream.cs
- CursorConverter.cs
- AddInPipelineAttributes.cs
- MultiTrigger.cs
- InternalsVisibleToAttribute.cs
- XmlReflectionImporter.cs
- RuntimeWrappedException.cs
- XmlSerializerAssemblyAttribute.cs
- DateTimeConverter.cs
- formatter.cs
- _ConnectionGroup.cs
- BuildTopDownAttribute.cs
- oledbmetadatacollectionnames.cs
- IsolatedStorageFileStream.cs
- PowerStatus.cs
- ModelPropertyDescriptor.cs
- ArglessEventHandlerProxy.cs
- ExpandCollapsePattern.cs
- HtmlFormParameterReader.cs
- FlowDocumentReaderAutomationPeer.cs
- OdbcCommand.cs
- RestHandler.cs
- ControlValuePropertyAttribute.cs
- InstanceDataCollectionCollection.cs
- XmlDocumentSerializer.cs
- _WebProxyDataBuilder.cs
- DesignOnlyAttribute.cs
- String.cs
- ReadContentAsBinaryHelper.cs
- Rotation3D.cs
- ToolboxComponentsCreatingEventArgs.cs
- StreamInfo.cs
- ConfigurationElementCollection.cs
- StringToken.cs
- NameValueSectionHandler.cs
- SchemaManager.cs
- WebDisplayNameAttribute.cs
- MetadataCacheItem.cs
- ScriptingScriptResourceHandlerSection.cs
- ColorComboBox.cs
- UIntPtr.cs
- TransformValueSerializer.cs
- BamlResourceDeserializer.cs
- SspiNegotiationTokenAuthenticator.cs
- IndexerNameAttribute.cs
- SemanticAnalyzer.cs
- LocalIdKeyIdentifierClause.cs
- FactoryRecord.cs
- ModelFactory.cs
- xmlfixedPageInfo.cs
- DataGridHeaderBorder.cs
- InvalidEnumArgumentException.cs
- WinHttpWebProxyFinder.cs
- LogEntryHeaderv1Deserializer.cs
- PrinterSettings.cs
- ScopelessEnumAttribute.cs
- HasCopySemanticsAttribute.cs
- XmlSchemaNotation.cs
- ObjectNavigationPropertyMapping.cs
- HelpKeywordAttribute.cs
- odbcmetadatacollectionnames.cs
- ModelTreeEnumerator.cs
- _PooledStream.cs
- WindowsFont.cs
- DependencyPropertyConverter.cs
- SchemaNames.cs
- CriticalHandle.cs
- StringFreezingAttribute.cs
- HttpChannelBindingToken.cs
- DataGridTextBoxColumn.cs
- ElementMarkupObject.cs
- FrameworkContentElementAutomationPeer.cs
- QilValidationVisitor.cs
- ButtonField.cs
- PrimitiveXmlSerializers.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- ToolTip.cs
- ListControl.cs
- XamlToRtfWriter.cs
- LayeredChannelListener.cs
- NestedContainer.cs
- StateItem.cs
- Geometry3D.cs
- FormatVersion.cs
- Atom10FormatterFactory.cs
- LoginUtil.cs
- AdapterDictionary.cs
- ServiceBusyException.cs
- ProtocolElementCollection.cs
- DataBindingExpressionBuilder.cs
- XmlCharacterData.cs
- DataColumnMappingCollection.cs
- Math.cs
- AssemblyAttributesGoHere.cs