Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ChannelManager.cs
- GenericTypeParameterBuilder.cs
- UIElementIsland.cs
- BitmapEffectDrawing.cs
- WindowsEditBox.cs
- FunctionUpdateCommand.cs
- DrawListViewItemEventArgs.cs
- SimpleExpression.cs
- WebConfigurationHost.cs
- FixUp.cs
- HtmlElementErrorEventArgs.cs
- MailMessageEventArgs.cs
- PriorityQueue.cs
- ParameterDataSourceExpression.cs
- WorkflowRuntimeServicesBehavior.cs
- WsrmTraceRecord.cs
- IdleTimeoutMonitor.cs
- ColorTransform.cs
- InkCanvasSelectionAdorner.cs
- SourceLineInfo.cs
- AutomationEventArgs.cs
- SqlDataReaderSmi.cs
- PropertyGridEditorPart.cs
- ClientTarget.cs
- CodePrimitiveExpression.cs
- basenumberconverter.cs
- BinaryNode.cs
- MiniConstructorInfo.cs
- QueryContinueDragEvent.cs
- FixedSOMPageElement.cs
- SelfSignedCertificate.cs
- StringOutput.cs
- SizeAnimationClockResource.cs
- TagPrefixAttribute.cs
- TextRangeProviderWrapper.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- ThicknessAnimationBase.cs
- PerformanceCounterNameAttribute.cs
- StrictModeSecurityHeaderElementInferenceEngine.cs
- OrderByBuilder.cs
- TextEditorCharacters.cs
- RoleService.cs
- ListBoxAutomationPeer.cs
- RenderCapability.cs
- SelfIssuedSamlTokenFactory.cs
- DesignerSerializerAttribute.cs
- LazyTextWriterCreator.cs
- SqlServer2KCompatibilityCheck.cs
- RequestStatusBarUpdateEventArgs.cs
- QilTypeChecker.cs
- FragmentNavigationEventArgs.cs
- CachedBitmap.cs
- CommandDesigner.cs
- ListParaClient.cs
- XmlComment.cs
- ImmutableObjectAttribute.cs
- IChannel.cs
- RadioButton.cs
- KeyValueConfigurationElement.cs
- NavigationPropertySingletonExpression.cs
- BamlTreeMap.cs
- MulticastNotSupportedException.cs
- TableRow.cs
- NonParentingControl.cs
- SiteMapNodeItem.cs
- SessionStateUtil.cs
- ExpressionWriter.cs
- BitmapMetadata.cs
- DataGridViewRowConverter.cs
- SmiEventSink_Default.cs
- ApplicationGesture.cs
- Hash.cs
- CapabilitiesSection.cs
- DocumentPageTextView.cs
- Logging.cs
- Ipv6Element.cs
- XhtmlBasicTextBoxAdapter.cs
- XMLDiffLoader.cs
- VisualStyleElement.cs
- IdentitySection.cs
- SafePointer.cs
- ResourcePool.cs
- PackWebRequest.cs
- DetailsViewUpdatedEventArgs.cs
- BaseTemplateCodeDomTreeGenerator.cs
- XhtmlBasicLinkAdapter.cs
- EntityKey.cs
- XPathSelectionIterator.cs
- ComponentManagerBroker.cs
- CodeStatement.cs
- SessionStateContainer.cs
- DataGridViewAutoSizeModeEventArgs.cs
- SettingsSection.cs
- ApplicationFileCodeDomTreeGenerator.cs
- RouteData.cs
- DataBoundControl.cs
- CloudCollection.cs
- SiteMap.cs
- ChtmlFormAdapter.cs
- WinEventTracker.cs