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
- BamlResourceDeserializer.cs
- PointCollectionConverter.cs
- Int16Storage.cs
- EnumType.cs
- Attributes.cs
- FtpWebResponse.cs
- QuaternionValueSerializer.cs
- Container.cs
- Comparer.cs
- ObjectManager.cs
- fixedPageContentExtractor.cs
- TemplateControlCodeDomTreeGenerator.cs
- TypeLibConverter.cs
- BufferedOutputStream.cs
- WebPartTransformer.cs
- TransactionCache.cs
- NameValuePair.cs
- TextRange.cs
- TextServicesProperty.cs
- OleServicesContext.cs
- XmlSchemaRedefine.cs
- WmlFormAdapter.cs
- WebCodeGenerator.cs
- DictionaryGlobals.cs
- CombinedTcpChannel.cs
- ConditionedDesigner.cs
- RenderData.cs
- ObjRef.cs
- Tablet.cs
- ParallelActivityDesigner.cs
- Rfc2898DeriveBytes.cs
- BrowserDefinition.cs
- TabletCollection.cs
- FlowDocumentReader.cs
- DataGridRelationshipRow.cs
- NumberFormatter.cs
- Sql8ConformanceChecker.cs
- LockCookie.cs
- WizardForm.cs
- ForeignKeyConstraint.cs
- TextRunCacheImp.cs
- SchemaImporter.cs
- ObjectParameterCollection.cs
- Timer.cs
- HybridDictionary.cs
- ElementInit.cs
- ResizeBehavior.cs
- AppDomain.cs
- ProtectedProviderSettings.cs
- MimeMultiPart.cs
- AtomServiceDocumentSerializer.cs
- Emitter.cs
- BooleanSwitch.cs
- CustomError.cs
- BasicAsyncResult.cs
- PropertyMetadata.cs
- BitmapFrameDecode.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- SecurityPolicySection.cs
- TextTreeFixupNode.cs
- TextureBrush.cs
- ProfessionalColors.cs
- TextServicesCompartment.cs
- MenuItem.cs
- FormsIdentity.cs
- BindingExpression.cs
- ScriptingRoleServiceSection.cs
- ProviderUtil.cs
- Int16Storage.cs
- ParameterToken.cs
- SerializationException.cs
- oledbmetadatacollectionnames.cs
- RectangleConverter.cs
- VectorAnimationBase.cs
- DataServiceQueryContinuation.cs
- ObjectDataSourceDisposingEventArgs.cs
- FormattedTextSymbols.cs
- BitmapEffect.cs
- ToolStripPanelDesigner.cs
- SimpleApplicationHost.cs
- MemberListBinding.cs
- FlowDocumentReaderAutomationPeer.cs
- Utility.cs
- ConnectionManagementSection.cs
- _ProxyRegBlob.cs
- TextFormatterContext.cs
- securitycriticaldata.cs
- EncryptedData.cs
- CleanUpVirtualizedItemEventArgs.cs
- GuidelineSet.cs
- Graphics.cs
- DesignerAutoFormatStyle.cs
- JoinElimination.cs
- StreamAsIStream.cs
- ConnectivityStatus.cs
- UrlParameterWriter.cs
- EntityDataReader.cs
- Size3DConverter.cs
- WebResponse.cs
- ObjectNotFoundException.cs