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
- SmiRecordBuffer.cs
- SystemEvents.cs
- SortKey.cs
- SelectionEditor.cs
- WindowsListViewItemStartMenu.cs
- PrintPreviewDialog.cs
- MaskedTextBox.cs
- Span.cs
- RepeaterCommandEventArgs.cs
- PerformanceCounterManager.cs
- GuidTagList.cs
- WebPartConnectionsCloseVerb.cs
- CompilerGeneratedAttribute.cs
- DataObjectFieldAttribute.cs
- ProtocolsConfigurationEntry.cs
- DockEditor.cs
- DictionaryBase.cs
- BitmapData.cs
- ColumnWidthChangingEvent.cs
- PersonalizationState.cs
- XmlBoundElement.cs
- Line.cs
- TableHeaderCell.cs
- CanonicalizationDriver.cs
- UniqueIdentifierService.cs
- GeometryConverter.cs
- ZipFileInfo.cs
- FullTextState.cs
- GregorianCalendarHelper.cs
- WebZoneDesigner.cs
- ElementHost.cs
- AsyncCodeActivity.cs
- PropertyChangeTracker.cs
- WindowsPen.cs
- GridViewHeaderRowPresenter.cs
- PeerNeighborManager.cs
- PropertyStore.cs
- HttpWebRequestElement.cs
- FileDialogCustomPlacesCollection.cs
- FixedPage.cs
- TextTreeUndoUnit.cs
- DataBindingsDialog.cs
- FixedLineResult.cs
- ManagementNamedValueCollection.cs
- SqlRetyper.cs
- TreeNodeCollection.cs
- WaveHeader.cs
- FacetValues.cs
- DynamicQueryableWrapper.cs
- BreakSafeBase.cs
- ComboBoxRenderer.cs
- TypeUnloadedException.cs
- DataControlButton.cs
- TreeWalkHelper.cs
- OdbcParameterCollection.cs
- Calendar.cs
- XmlAtomicValue.cs
- AccessViolationException.cs
- CultureTable.cs
- BookmarkList.cs
- ConfigurationManagerInternal.cs
- SizeConverter.cs
- Point4D.cs
- QueueNameHelper.cs
- StylusButtonEventArgs.cs
- OutKeywords.cs
- DataStreams.cs
- ToolStripItem.cs
- XDRSchema.cs
- XmlSchemaException.cs
- DataGridItemEventArgs.cs
- SqlConnectionStringBuilder.cs
- HtmlButton.cs
- Page.cs
- ServerValidateEventArgs.cs
- BlockUIContainer.cs
- FormViewUpdateEventArgs.cs
- QueryExtender.cs
- GeometryModel3D.cs
- EpmSyndicationContentSerializer.cs
- ListCollectionView.cs
- MessageAction.cs
- SqlCacheDependencySection.cs
- ObjectStateEntry.cs
- DetailsViewRowCollection.cs
- ConvertersCollection.cs
- PasswordRecovery.cs
- EditableRegion.cs
- SchemaElementLookUpTable.cs
- securitycriticaldataformultiplegetandset.cs
- CodeTryCatchFinallyStatement.cs
- BufferedStream.cs
- ColorAnimationUsingKeyFrames.cs
- X509Certificate2Collection.cs
- DatagridviewDisplayedBandsData.cs
- COM2ColorConverter.cs
- Interop.cs
- SqlIdentifier.cs
- DateTimeUtil.cs
- ScriptingRoleServiceSection.cs