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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridRelationshipRow.cs
- DependencyPropertyKey.cs
- GroupBoxRenderer.cs
- AssemblyResourceLoader.cs
- ColumnMapCopier.cs
- WebBrowserUriTypeConverter.cs
- IntranetCredentialPolicy.cs
- ProcessHostMapPath.cs
- ControlCodeDomSerializer.cs
- X509ThumbprintKeyIdentifierClause.cs
- WindowsHyperlink.cs
- TextServicesProperty.cs
- CallbackHandler.cs
- SerializeAbsoluteContext.cs
- DataGridViewTextBoxColumn.cs
- XsltSettings.cs
- CFStream.cs
- FormViewInsertEventArgs.cs
- relpropertyhelper.cs
- UIElementPropertyUndoUnit.cs
- BitmapImage.cs
- Scheduling.cs
- DocumentXPathNavigator.cs
- LateBoundBitmapDecoder.cs
- IgnoreSection.cs
- MinimizableAttributeTypeConverter.cs
- Pen.cs
- Sentence.cs
- EncoderBestFitFallback.cs
- TemplatedWizardStep.cs
- WindowsRichEdit.cs
- DetailsViewInsertEventArgs.cs
- NavigationProgressEventArgs.cs
- StateRuntime.cs
- GridViewDeleteEventArgs.cs
- Selector.cs
- OdbcError.cs
- WsdlInspector.cs
- UIElementCollection.cs
- X509Extension.cs
- ConstNode.cs
- BasePattern.cs
- SafeSystemMetrics.cs
- IdleTimeoutMonitor.cs
- FileVersionInfo.cs
- MenuItemBinding.cs
- ExtendedPropertyCollection.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- LongTypeConverter.cs
- EventLogPermissionEntryCollection.cs
- ControlPaint.cs
- KeyManager.cs
- ColumnMapProcessor.cs
- Trace.cs
- ComponentDispatcherThread.cs
- EntityDataSourceReferenceGroup.cs
- WorkflowApplicationTerminatedException.cs
- InternalTransaction.cs
- PropertyTab.cs
- PageClientProxyGenerator.cs
- coordinator.cs
- X509InitiatorCertificateServiceElement.cs
- ToolBarButton.cs
- SettingsPropertyNotFoundException.cs
- BrushConverter.cs
- DataGridViewRowCollection.cs
- HyperLinkStyle.cs
- Sql8ExpressionRewriter.cs
- _ConnectOverlappedAsyncResult.cs
- UITypeEditors.cs
- XPathNavigatorException.cs
- TextParentUndoUnit.cs
- XmlNodeList.cs
- NativeMethods.cs
- EdmConstants.cs
- Base64Encoder.cs
- DataColumnChangeEvent.cs
- Size.cs
- DesignerInterfaces.cs
- OleDbException.cs
- ComplexType.cs
- ProviderSettings.cs
- WebBrowserUriTypeConverter.cs
- DataGridViewColumnEventArgs.cs
- AppDomainCompilerProxy.cs
- DesignerActionTextItem.cs
- UrlMappingsModule.cs
- XsdValidatingReader.cs
- Expander.cs
- SourceItem.cs
- PropertyIDSet.cs
- DNS.cs
- RemotingException.cs
- NoneExcludedImageIndexConverter.cs
- ComboBoxAutomationPeer.cs
- PathTooLongException.cs
- MetabaseReader.cs
- LicenseProviderAttribute.cs
- LingerOption.cs
- RadioButtonStandardAdapter.cs