Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / ByteStack.cs / 1305376 / 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
- TextServicesManager.cs
- DocumentApplication.cs
- SiteMapNodeItem.cs
- DoubleLinkList.cs
- SoapAttributeAttribute.cs
- GPPOINT.cs
- DoubleAnimation.cs
- SafeRightsManagementEnvironmentHandle.cs
- DataGridItemCollection.cs
- RoleGroup.cs
- OdbcTransaction.cs
- SearchForVirtualItemEventArgs.cs
- CharEnumerator.cs
- StrongNameKeyPair.cs
- HashHelper.cs
- FormsAuthenticationConfiguration.cs
- ToolStripDesigner.cs
- Vector.cs
- GeometryDrawing.cs
- InkCanvasFeedbackAdorner.cs
- XmlTextReader.cs
- OLEDB_Util.cs
- BaseDataBoundControl.cs
- AccessorTable.cs
- ContractTypeNameElement.cs
- SQLInt32.cs
- ToolStripItem.cs
- ServiceEndpointElement.cs
- VSWCFServiceContractGenerator.cs
- EqualityComparer.cs
- UdpMessageProperty.cs
- RequestCacheValidator.cs
- HandlerFactoryCache.cs
- UIElementAutomationPeer.cs
- Deflater.cs
- _Rfc2616CacheValidators.cs
- TextElementCollectionHelper.cs
- ContentControl.cs
- XmlSchemaType.cs
- WindowsNonControl.cs
- BaseTemplateParser.cs
- XslException.cs
- IisTraceWebEventProvider.cs
- HostedElements.cs
- EventToken.cs
- _NegoState.cs
- XmlObjectSerializerReadContext.cs
- Sql8ExpressionRewriter.cs
- PanelDesigner.cs
- MulticastOption.cs
- InfiniteIntConverter.cs
- DbProviderFactories.cs
- DeviceContexts.cs
- AsyncCompletedEventArgs.cs
- ActiveXSerializer.cs
- PrintDocument.cs
- SettingsPropertyCollection.cs
- XmlLanguageConverter.cs
- HashMembershipCondition.cs
- ProjectionCamera.cs
- MailAddressCollection.cs
- EntityDesignerUtils.cs
- GPRECT.cs
- RijndaelCryptoServiceProvider.cs
- MatrixStack.cs
- TypeElement.cs
- ClientRuntimeConfig.cs
- LayoutInformation.cs
- SerialErrors.cs
- BindingMAnagerBase.cs
- OleDbCommand.cs
- StreamHelper.cs
- PageVisual.cs
- UDPClient.cs
- Paragraph.cs
- IChannel.cs
- Button.cs
- HttpWriter.cs
- TypedReference.cs
- BaseAsyncResult.cs
- HostedHttpTransportManager.cs
- EntityCommandCompilationException.cs
- AggregateException.cs
- CqlGenerator.cs
- StateDesigner.LayoutSelectionGlyph.cs
- ConstraintStruct.cs
- LocatorGroup.cs
- PropertyChangedEventArgs.cs
- SrgsElementList.cs
- LayoutManager.cs
- MultipleViewProviderWrapper.cs
- KeyValueSerializer.cs
- PriorityBinding.cs
- SoapTypeAttribute.cs
- XmlBoundElement.cs
- TaskDesigner.cs
- BypassElement.cs
- SettingsSavedEventArgs.cs
- ResourceReferenceKeyNotFoundException.cs
- BaseCAMarshaler.cs