Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Xml / System / Xml / ByteStack.cs / 1 / ByteStack.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; namespace System.Xml { // This stack is designed to minimize object creation for the // objects being stored in the stack by allowing them to be // re-used over time. It basically pushes the objects creating // a high water mark then as Pop() is called they are not removed // so that next time Push() is called it simply returns the last // object that was already on the stack. internal class ByteStack { private byte[] stack; private int growthRate; private int top; private int size; public ByteStack(int growthRate) { this.growthRate = growthRate; top = 0; stack = new byte[growthRate]; size = growthRate; } public void Push(byte data) { if (size == top) { byte[] newstack = new byte[size + growthRate]; if (top > 0) { Buffer.BlockCopy(stack, 0, newstack, 0, top); } stack = newstack; size += growthRate; } stack[top++] = data; } public byte Pop() { if (top > 0) { return stack[--top]; } else { return 0; } } public byte Peek() { if (top > 0) { return stack[top - 1]; } else { return 0; } } public int Length { get { return top; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; namespace System.Xml { // This stack is designed to minimize object creation for the // objects being stored in the stack by allowing them to be // re-used over time. It basically pushes the objects creating // a high water mark then as Pop() is called they are not removed // so that next time Push() is called it simply returns the last // object that was already on the stack. internal class ByteStack { private byte[] stack; private int growthRate; private int top; private int size; public ByteStack(int growthRate) { this.growthRate = growthRate; top = 0; stack = new byte[growthRate]; size = growthRate; } public void Push(byte data) { if (size == top) { byte[] newstack = new byte[size + growthRate]; if (top > 0) { Buffer.BlockCopy(stack, 0, newstack, 0, top); } stack = newstack; size += growthRate; } stack[top++] = data; } public byte Pop() { if (top > 0) { return stack[--top]; } else { return 0; } } public byte Peek() { if (top > 0) { return stack[top - 1]; } else { return 0; } } public int Length { get { return top; } } } } // 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
- ConnectionPoint.cs
- PerformanceCountersElement.cs
- ExceptionValidationRule.cs
- ThrowOnMultipleAssignment.cs
- TokenBasedSet.cs
- CannotUnloadAppDomainException.cs
- ToolStripSplitButton.cs
- C14NUtil.cs
- TouchPoint.cs
- OAVariantLib.cs
- EditorZone.cs
- SignatureDescription.cs
- PropertyTabAttribute.cs
- MenuItemCollection.cs
- ComponentResourceKey.cs
- OdbcCommand.cs
- WindowsAltTab.cs
- ImageListDesigner.cs
- ContourSegment.cs
- ObjectDataSourceSelectingEventArgs.cs
- ButtonBase.cs
- RuntimeResourceSet.cs
- ControlType.cs
- Scene3D.cs
- SqlIdentifier.cs
- SessionStateSection.cs
- SevenBitStream.cs
- Peer.cs
- TextRunCacheImp.cs
- AnimatedTypeHelpers.cs
- SchemaElementLookUpTable.cs
- infer.cs
- UIPropertyMetadata.cs
- StringSource.cs
- ProtocolsConfigurationHandler.cs
- LocalizableAttribute.cs
- IIS7WorkerRequest.cs
- InlineUIContainer.cs
- TypeKeyValue.cs
- FamilyCollection.cs
- TextElementCollectionHelper.cs
- ChannelDemuxer.cs
- ValueOfAction.cs
- LoadedOrUnloadedOperation.cs
- SortedList.cs
- WindowsIPAddress.cs
- SqlCommandSet.cs
- ServiceReflector.cs
- ReadOnlyAttribute.cs
- ManipulationVelocities.cs
- SQLResource.cs
- DoubleSumAggregationOperator.cs
- TextTreeTextNode.cs
- EventHandlingScope.cs
- WorkflowPrinting.cs
- ViewgenContext.cs
- Point3D.cs
- IsolationInterop.cs
- DBDataPermission.cs
- MetafileHeaderEmf.cs
- WCFServiceClientProxyGenerator.cs
- DbConnectionInternal.cs
- SafeNativeMethods.cs
- UIHelper.cs
- ColorTranslator.cs
- ScriptResourceDefinition.cs
- ContainerParagraph.cs
- IBuiltInEvidence.cs
- SqlGenericUtil.cs
- Glyph.cs
- arclist.cs
- TailPinnedEventArgs.cs
- WindowsScroll.cs
- AnnotationHighlightLayer.cs
- PropertyCollection.cs
- DataViewManager.cs
- SqlTriggerContext.cs
- NameNode.cs
- DiagnosticStrings.cs
- OleDbDataAdapter.cs
- BitmapPalette.cs
- AttributeProviderAttribute.cs
- ContextBase.cs
- CollectionViewGroup.cs
- AssociationSetMetadata.cs
- LingerOption.cs
- ArrayWithOffset.cs
- PositiveTimeSpanValidator.cs
- CallSite.cs
- StylusPlugin.cs
- CommandID.cs
- CollectionViewGroup.cs
- SimpleBitVector32.cs
- ToolboxSnapDragDropEventArgs.cs
- TransactionBehavior.cs
- SslStream.cs
- SettingsPropertyNotFoundException.cs
- PropertyTab.cs
- DmlSqlGenerator.cs
- NavigationHelper.cs