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
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Slider.cs
- ScrollEventArgs.cs
- _SafeNetHandles.cs
- GraphicsState.cs
- WebServiceEnumData.cs
- StringFunctions.cs
- WebRequestModulesSection.cs
- AsymmetricKeyExchangeDeformatter.cs
- InkCanvasSelection.cs
- HtmlLink.cs
- BuildProviderCollection.cs
- MetadataArtifactLoaderCompositeResource.cs
- prompt.cs
- CmsInterop.cs
- ReadOnlyDictionary.cs
- BoundField.cs
- VisualTreeUtils.cs
- CodeObject.cs
- UndoUnit.cs
- Literal.cs
- _BufferOffsetSize.cs
- ActivationServices.cs
- WorkflowDesigner.cs
- TraceUtility.cs
- HtmlEmptyTagControlBuilder.cs
- bidPrivateBase.cs
- ActivityDesignerAccessibleObject.cs
- DataRecordInternal.cs
- UserPersonalizationStateInfo.cs
- OleDbCommandBuilder.cs
- HttpResponseHeader.cs
- KoreanCalendar.cs
- RemotingClientProxy.cs
- XmlConvert.cs
- FilteredXmlReader.cs
- ResourceType.cs
- UserControl.cs
- SendParametersContent.cs
- AssociationTypeEmitter.cs
- Table.cs
- PopOutPanel.cs
- WorkflowMarkupSerializerMapping.cs
- View.cs
- XmlSchemaIdentityConstraint.cs
- XPathNodeIterator.cs
- LocalServiceSecuritySettings.cs
- AutomationPeer.cs
- LinkLabel.cs
- ClientSponsor.cs
- NativeMethods.cs
- Line.cs
- ContextItemManager.cs
- AppSettingsSection.cs
- SecureUICommand.cs
- SafeLocalMemHandle.cs
- CodeExpressionStatement.cs
- ColumnMapVisitor.cs
- SiteMapPath.cs
- QuotedPrintableStream.cs
- IisTraceWebEventProvider.cs
- TimeIntervalCollection.cs
- Parameter.cs
- SQLCharsStorage.cs
- ConfigurationLocation.cs
- ErrorItem.cs
- CodeTypeReferenceExpression.cs
- RuntimeEnvironment.cs
- SQlBooleanStorage.cs
- AsyncDataRequest.cs
- ContentFilePart.cs
- PreservationFileReader.cs
- XmlSchemaObjectCollection.cs
- AxParameterData.cs
- TransformProviderWrapper.cs
- LocationChangedEventArgs.cs
- RSAOAEPKeyExchangeFormatter.cs
- OrderedEnumerableRowCollection.cs
- LayoutUtils.cs
- QilInvokeLateBound.cs
- DataGridPagerStyle.cs
- Dictionary.cs
- ComNativeDescriptor.cs
- TaiwanLunisolarCalendar.cs
- ConsumerConnectionPointCollection.cs
- SQLMembershipProvider.cs
- HttpResponseHeader.cs
- DrawingImage.cs
- FastEncoderWindow.cs
- SectionInput.cs
- CryptoApi.cs
- TextTreeTextNode.cs
- SoapElementAttribute.cs
- AtomMaterializer.cs
- returneventsaver.cs
- SharedPerformanceCounter.cs
- CompositeFontInfo.cs
- Deflater.cs
- SecurityPermission.cs
- WindowsPrincipal.cs
- FormsAuthenticationTicket.cs