Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- SqlBinder.cs
- SqlProfileProvider.cs
- RoutedUICommand.cs
- Expressions.cs
- SchemaNotation.cs
- HashCodeCombiner.cs
- ListMarkerLine.cs
- ArrayConverter.cs
- CodeArrayCreateExpression.cs
- MenuBase.cs
- ApplyTemplatesAction.cs
- DecimalKeyFrameCollection.cs
- MenuItem.cs
- InvokeMethodActivity.cs
- PasswordBox.cs
- SocketAddress.cs
- CodeTypeParameter.cs
- GroupQuery.cs
- PointCollectionValueSerializer.cs
- WizardForm.cs
- SQLDoubleStorage.cs
- LazyInitializer.cs
- HttpResponseHeader.cs
- ReadOnlyPropertyMetadata.cs
- UnsafeNativeMethods.cs
- HyperLink.cs
- HelpProvider.cs
- AutomationAttributeInfo.cs
- XamlBrushSerializer.cs
- ScopeCompiler.cs
- XDRSchema.cs
- XmlSchemaAppInfo.cs
- SoundPlayer.cs
- KeyGestureConverter.cs
- FileNameEditor.cs
- TdsParserSafeHandles.cs
- InternalDispatchObject.cs
- MetadataArtifactLoaderFile.cs
- RoutedEventValueSerializer.cs
- CurrencyManager.cs
- DocumentAutomationPeer.cs
- DataServiceQueryOfT.cs
- RefType.cs
- InternalRelationshipCollection.cs
- QueueSurrogate.cs
- DesignTimeValidationFeature.cs
- Error.cs
- SortDescriptionCollection.cs
- CellCreator.cs
- RectIndependentAnimationStorage.cs
- ReadOnlyHierarchicalDataSource.cs
- VoiceSynthesis.cs
- BitmapMetadata.cs
- DataRelationCollection.cs
- Menu.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- CalendarSelectionChangedEventArgs.cs
- WebConfigurationHostFileChange.cs
- SafeFileMappingHandle.cs
- XmlQueryType.cs
- BackgroundWorker.cs
- ClientBuildManager.cs
- Identity.cs
- ParentQuery.cs
- MenuItemStyleCollectionEditor.cs
- FixUpCollection.cs
- RefreshEventArgs.cs
- TypeBuilder.cs
- ExpandoObject.cs
- WeakHashtable.cs
- AutoResetEvent.cs
- ping.cs
- log.cs
- ListSurrogate.cs
- DateTimeAutomationPeer.cs
- WeakEventTable.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- SqlServer2KCompatibilityCheck.cs
- WinFormsSecurity.cs
- TextEditorMouse.cs
- StreamInfo.cs
- CompModSwitches.cs
- FirstMatchCodeGroup.cs
- ValidationHelper.cs
- AccessedThroughPropertyAttribute.cs
- TdsParserStateObject.cs
- TextOutput.cs
- UrlPropertyAttribute.cs
- InternalTransaction.cs
- PlaceHolder.cs
- ZipIOBlockManager.cs
- ThemeInfoAttribute.cs
- CryptoProvider.cs
- XPathDocument.cs
- CheckBoxFlatAdapter.cs
- ApplicationId.cs
- SerialPinChanges.cs
- CellParagraph.cs
- ControlType.cs
- CodeExpressionCollection.cs