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
- Knowncolors.cs
- ExtenderProvidedPropertyAttribute.cs
- ServerValidateEventArgs.cs
- ServiceOperationUIEditor.cs
- ping.cs
- GridViewRow.cs
- WebPartConnectVerb.cs
- NullableIntSumAggregationOperator.cs
- validation.cs
- ResourceReferenceExpression.cs
- ConditionChanges.cs
- ZipIOExtraFieldZip64Element.cs
- CounterCreationDataConverter.cs
- __FastResourceComparer.cs
- RtfToXamlLexer.cs
- DrawingImage.cs
- InputBindingCollection.cs
- Pen.cs
- BackEase.cs
- WindowsEditBoxRange.cs
- TypedColumnHandler.cs
- SspiSafeHandles.cs
- GCHandleCookieTable.cs
- NumberFormatInfo.cs
- FileEnumerator.cs
- TableItemPatternIdentifiers.cs
- SafeArrayTypeMismatchException.cs
- XmlCDATASection.cs
- ExpressionDumper.cs
- Delegate.cs
- AsymmetricCryptoHandle.cs
- XmlArrayItemAttribute.cs
- SqlClientWrapperSmiStream.cs
- ContainerActivationHelper.cs
- RequestBringIntoViewEventArgs.cs
- ClassicBorderDecorator.cs
- IntegerValidator.cs
- TemplateBindingExtension.cs
- ApplicationFileParser.cs
- NativeMethods.cs
- EntitySqlQueryState.cs
- CounterSetInstance.cs
- ConnectionManagementElementCollection.cs
- ViewBase.cs
- Compress.cs
- InputLanguage.cs
- DataPointer.cs
- AxImporter.cs
- DbParameterCollectionHelper.cs
- ScrollPattern.cs
- ScrollChangedEventArgs.cs
- DelegateBodyWriter.cs
- EncoderBestFitFallback.cs
- PerformanceCounterCategory.cs
- IWorkflowDebuggerService.cs
- BitmapEffectGroup.cs
- XmlSchemaCollection.cs
- DelegatingTypeDescriptionProvider.cs
- TemplateBindingExtension.cs
- WorkflowStateRollbackService.cs
- Misc.cs
- TypedTableBase.cs
- TargetInvocationException.cs
- InputProcessorProfilesLoader.cs
- SerializerDescriptor.cs
- UserControl.cs
- CodeObjectCreateExpression.cs
- Overlapped.cs
- Listbox.cs
- _NetRes.cs
- SspiHelper.cs
- SmiEventSink_Default.cs
- Environment.cs
- WebBrowserHelper.cs
- RightsManagementPermission.cs
- DataObjectFieldAttribute.cs
- ZipIOBlockManager.cs
- Brush.cs
- Section.cs
- PolicyDesigner.cs
- XhtmlBasicPageAdapter.cs
- HtmlInputControl.cs
- ParentQuery.cs
- OletxTransactionManager.cs
- StagingAreaInputItem.cs
- COM2ColorConverter.cs
- MobileErrorInfo.cs
- CapacityStreamGeometryContext.cs
- ImageConverter.cs
- TextRenderingModeValidation.cs
- ByteRangeDownloader.cs
- SamlDoNotCacheCondition.cs
- ProcessThreadCollection.cs
- ScrollItemPattern.cs
- BaseTemplateCodeDomTreeGenerator.cs
- DbParameterCollectionHelper.cs
- FieldTemplateUserControl.cs
- DBCommandBuilder.cs
- RequestResponse.cs
- StrokeRenderer.cs