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
- FileLogRecordHeader.cs
- Point.cs
- ImpersonationContext.cs
- GACMembershipCondition.cs
- UnsafeNativeMethodsCLR.cs
- PackageProperties.cs
- NamedObject.cs
- BaseTemplateCodeDomTreeGenerator.cs
- XmlName.cs
- TextServicesPropertyRanges.cs
- DTCTransactionManager.cs
- ReadOnlyDictionary.cs
- EntityDataSourceState.cs
- RepeaterItemEventArgs.cs
- AddInServer.cs
- PointF.cs
- HttpVersion.cs
- Random.cs
- TextSimpleMarkerProperties.cs
- Conditional.cs
- FormsIdentity.cs
- EventLogTraceListener.cs
- TextParagraphCache.cs
- XmlSchemaInferenceException.cs
- Schema.cs
- InitializationEventAttribute.cs
- OleDbParameter.cs
- ModelPropertyCollectionImpl.cs
- ConfigurationHelpers.cs
- DES.cs
- ContextQuery.cs
- TreeNodeConverter.cs
- __FastResourceComparer.cs
- SynchronizationContext.cs
- EntityDataSourceContainerNameConverter.cs
- IPPacketInformation.cs
- TrackBarRenderer.cs
- DataSetFieldSchema.cs
- SerializationStore.cs
- XmlToDatasetMap.cs
- ToolStripOverflowButton.cs
- BooleanKeyFrameCollection.cs
- MessageQueueCriteria.cs
- SatelliteContractVersionAttribute.cs
- ColorConvertedBitmapExtension.cs
- DoubleAnimationClockResource.cs
- ValidationPropertyAttribute.cs
- TrayIconDesigner.cs
- TextAnchor.cs
- SharedUtils.cs
- CountdownEvent.cs
- X509RawDataKeyIdentifierClause.cs
- __Filters.cs
- DataTableMapping.cs
- StreamUpdate.cs
- ConfigXmlSignificantWhitespace.cs
- BatchServiceHost.cs
- FunctionNode.cs
- TypeNameConverter.cs
- ServiceDeploymentInfo.cs
- LocationUpdates.cs
- FontCollection.cs
- XmlElementAttributes.cs
- ChildTable.cs
- SettingsSavedEventArgs.cs
- XPathNavigatorReader.cs
- DBPropSet.cs
- DnsPermission.cs
- XamlReader.cs
- BoundsDrawingContextWalker.cs
- PerfCounters.cs
- C14NUtil.cs
- SyntaxCheck.cs
- FieldMetadata.cs
- ButtonAutomationPeer.cs
- SolidColorBrush.cs
- MgmtResManager.cs
- PropertyTabChangedEvent.cs
- SelectionEditingBehavior.cs
- SerializationObjectManager.cs
- CustomValidator.cs
- MessageFormatterConverter.cs
- ContainerAction.cs
- X509AsymmetricSecurityKey.cs
- ZoomComboBox.cs
- __TransparentProxy.cs
- DataControlLinkButton.cs
- PtsPage.cs
- BoundColumn.cs
- TextAdaptor.cs
- ProfessionalColors.cs
- MouseDevice.cs
- HyperLinkField.cs
- IDispatchConstantAttribute.cs
- HttpRawResponse.cs
- IndexingContentUnit.cs
- TreeNodeSelectionProcessor.cs
- TextRange.cs
- _BufferOffsetSize.cs
- BamlLocalizationDictionary.cs