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
- WebAdminConfigurationHelper.cs
- RelationshipDetailsCollection.cs
- propertytag.cs
- WebBrowser.cs
- dbdatarecord.cs
- ReliabilityContractAttribute.cs
- ProcessHost.cs
- ZoomingMessageFilter.cs
- HTMLTextWriter.cs
- BitmapEffectInputConnector.cs
- ReachPrintTicketSerializerAsync.cs
- SchemaImporterExtensionElementCollection.cs
- SingleSelectRootGridEntry.cs
- PathFigureCollectionConverter.cs
- UnauthorizedWebPart.cs
- GenerateHelper.cs
- Interlocked.cs
- ArgumentDesigner.xaml.cs
- CheckBox.cs
- GridViewPageEventArgs.cs
- TextTreeObjectNode.cs
- ZipFileInfoCollection.cs
- BamlStream.cs
- PropertyMap.cs
- PartBasedPackageProperties.cs
- InternalControlCollection.cs
- BindingBase.cs
- RadioButtonPopupAdapter.cs
- CallbackValidator.cs
- BuildProvider.cs
- BaseTemplateCodeDomTreeGenerator.cs
- Int32.cs
- NativeStructs.cs
- ParsedAttributeCollection.cs
- BamlVersionHeader.cs
- CodeCatchClauseCollection.cs
- PackageDigitalSignatureManager.cs
- ObjectDataProvider.cs
- AssemblySettingAttributes.cs
- CaseStatement.cs
- ValidatorCompatibilityHelper.cs
- DesignerActionMethodItem.cs
- RenderData.cs
- DataGridViewCellConverter.cs
- UnsafeNativeMethods.cs
- ColorPalette.cs
- GeometryGroup.cs
- TabletDevice.cs
- PrimitiveType.cs
- LocalFileSettingsProvider.cs
- FormViewDeleteEventArgs.cs
- EntityDataSourceSelectingEventArgs.cs
- ServiceThrottlingElement.cs
- MouseCaptureWithinProperty.cs
- CombinedGeometry.cs
- SelectedDatesCollection.cs
- DesignerProperties.cs
- AddInStore.cs
- RichTextBox.cs
- MetafileHeaderWmf.cs
- WS2007HttpBindingCollectionElement.cs
- EdmToObjectNamespaceMap.cs
- _ListenerRequestStream.cs
- IsolatedStorageFile.cs
- StateFinalizationDesigner.cs
- EtwTrace.cs
- Menu.cs
- FormsAuthentication.cs
- PrintSystemException.cs
- UpdatePanelTrigger.cs
- TextBoxBase.cs
- HttpContextWrapper.cs
- WebPartPersonalization.cs
- PerformanceCounterPermissionEntry.cs
- CommandLibraryHelper.cs
- QueryExecutionOption.cs
- AnimationTimeline.cs
- XPathBuilder.cs
- recordstatefactory.cs
- SourceElementsCollection.cs
- PathStreamGeometryContext.cs
- WebHeaderCollection.cs
- X509Certificate2Collection.cs
- OutputCacheProfileCollection.cs
- XmlEncoding.cs
- GenerateTemporaryAssemblyTask.cs
- TimeStampChecker.cs
- SystemKeyConverter.cs
- OracleSqlParser.cs
- WebPartManagerInternals.cs
- ReflectEventDescriptor.cs
- SafeBitVector32.cs
- WpfKnownMemberInvoker.cs
- XmlIncludeAttribute.cs
- DesignerTransaction.cs
- TemplateControlBuildProvider.cs
- HtmlInputReset.cs
- ComboBoxDesigner.cs
- PositiveTimeSpanValidator.cs
- DataGridColumnHeader.cs