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
- DataRecordObjectView.cs
- BStrWrapper.cs
- ReturnEventArgs.cs
- MarshalByRefObject.cs
- UniqueIdentifierService.cs
- MouseEventArgs.cs
- TransformPatternIdentifiers.cs
- EnumValAlphaComparer.cs
- TemplateKeyConverter.cs
- SqlGatherConsumedAliases.cs
- XamlHostingSection.cs
- Brush.cs
- assemblycache.cs
- XmlCharType.cs
- CollectionChangedEventManager.cs
- BinaryConverter.cs
- ApplyTemplatesAction.cs
- ManagementScope.cs
- OpenFileDialog.cs
- Query.cs
- ResourceReferenceKeyNotFoundException.cs
- DefaultSection.cs
- WindowsFormsHelpers.cs
- TextViewSelectionProcessor.cs
- OracleLob.cs
- AgileSafeNativeMemoryHandle.cs
- DiscoveryClientChannelFactory.cs
- MediaScriptCommandRoutedEventArgs.cs
- EntityDataSourceContextDisposingEventArgs.cs
- SlipBehavior.cs
- DependencyPropertyAttribute.cs
- XmlJsonWriter.cs
- BypassElementCollection.cs
- ExpressionPrinter.cs
- ConfigXmlComment.cs
- LogicalCallContext.cs
- ToolBarButtonDesigner.cs
- SupportsPreviewControlAttribute.cs
- FixedSOMContainer.cs
- Win32Native.cs
- ObjectKeyFrameCollection.cs
- OutputCacheProfileCollection.cs
- XamlVector3DCollectionSerializer.cs
- QilFactory.cs
- _ContextAwareResult.cs
- StringFreezingAttribute.cs
- ObjectComplexPropertyMapping.cs
- XmlAttributes.cs
- MessageDecoder.cs
- Propagator.JoinPropagator.cs
- EmptyQuery.cs
- FileDialog.cs
- DataGridViewControlCollection.cs
- Vertex.cs
- SourceItem.cs
- Misc.cs
- OwnerDrawPropertyBag.cs
- RoleGroupCollection.cs
- MetabaseSettings.cs
- _AuthenticationState.cs
- BeginEvent.cs
- AuditLogLocation.cs
- DetailsViewUpdatedEventArgs.cs
- ObjectTokenCategory.cs
- LayoutEditorPart.cs
- WindowsTokenRoleProvider.cs
- SqlParameter.cs
- JulianCalendar.cs
- TimeZone.cs
- TableLayoutCellPaintEventArgs.cs
- DbConnectionPoolCounters.cs
- InternalConfigRoot.cs
- PlainXmlDeserializer.cs
- ViewValidator.cs
- DocumentOrderQuery.cs
- OuterGlowBitmapEffect.cs
- RegisterResponseInfo.cs
- DataTableClearEvent.cs
- Decoder.cs
- XmlnsDefinitionAttribute.cs
- GridView.cs
- RTTrackingProfile.cs
- CodeExpressionCollection.cs
- ServiceMemoryGates.cs
- AccessorTable.cs
- SqlBulkCopyColumnMapping.cs
- _ScatterGatherBuffers.cs
- RoleGroup.cs
- CreateRefExpr.cs
- VBIdentifierDesigner.xaml.cs
- MachineKeyConverter.cs
- Debug.cs
- BrowserCapabilitiesFactory.cs
- EncryptedReference.cs
- PipelineDeploymentState.cs
- AvTraceDetails.cs
- Substitution.cs
- MessageBox.cs
- TemplateManager.cs
- DataGridViewCellFormattingEventArgs.cs