Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- MultipleCopiesCollection.cs
- WebScriptClientGenerator.cs
- MenuItem.cs
- Pts.cs
- DesignerVerb.cs
- TextEffectResolver.cs
- DrawingVisual.cs
- ChangeConflicts.cs
- XmlAttributeAttribute.cs
- CodeDefaultValueExpression.cs
- PrePrepareMethodAttribute.cs
- EntityDataSourceReferenceGroup.cs
- TTSEvent.cs
- NativeObjectSecurity.cs
- StreamUpgradeBindingElement.cs
- SqlLiftIndependentRowExpressions.cs
- ObjectQueryState.cs
- Char.cs
- CounterSample.cs
- Mapping.cs
- LicenseManager.cs
- httpserverutility.cs
- returneventsaver.cs
- basenumberconverter.cs
- Win32PrintDialog.cs
- TaskHelper.cs
- UInt16Storage.cs
- SortDescriptionCollection.cs
- NavigationProperty.cs
- SynchronizedDispatch.cs
- HtmlAnchor.cs
- Int32AnimationUsingKeyFrames.cs
- PointHitTestParameters.cs
- ContentType.cs
- SqlNodeAnnotations.cs
- ellipse.cs
- AssemblySettingAttributes.cs
- CodeTypeReferenceCollection.cs
- TransformValueSerializer.cs
- DropAnimation.xaml.cs
- TreeWalkHelper.cs
- InvokePatternIdentifiers.cs
- StrokeNodeEnumerator.cs
- SHA384.cs
- ExpressionBindingCollection.cs
- Comparer.cs
- TrackBarRenderer.cs
- SafeBitVector32.cs
- DBAsyncResult.cs
- CompleteWizardStep.cs
- CacheRequest.cs
- LambdaCompiler.Lambda.cs
- codemethodreferenceexpression.cs
- HtmlInputFile.cs
- Light.cs
- SamlAuthenticationStatement.cs
- LineGeometry.cs
- OAVariantLib.cs
- AsyncResult.cs
- Preprocessor.cs
- ComNativeDescriptor.cs
- AuditLogLocation.cs
- ThreadExceptionEvent.cs
- DataTemplate.cs
- OdbcRowUpdatingEvent.cs
- StyleReferenceConverter.cs
- DataTableReader.cs
- ResponseStream.cs
- WorkItem.cs
- CompoundFileReference.cs
- UIElement3DAutomationPeer.cs
- XPathExpr.cs
- httpapplicationstate.cs
- PackageController.cs
- DeclarationUpdate.cs
- SignedInfo.cs
- XmlQueryTypeFactory.cs
- TypeForwardedToAttribute.cs
- TreeViewEvent.cs
- XPathNode.cs
- SettingsPropertyCollection.cs
- ExecutionEngineException.cs
- SystemResourceHost.cs
- BindingsCollection.cs
- BindingMemberInfo.cs
- TransformCollection.cs
- CodePrimitiveExpression.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- NamespaceQuery.cs
- ToolStripControlHost.cs
- HtmlInputButton.cs
- ListBindableAttribute.cs
- Binding.cs
- GeneralTransform.cs
- Pkcs7Signer.cs
- MbpInfo.cs
- TraceContext.cs
- _emptywebproxy.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- MouseGestureConverter.cs