Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- DataBindingExpressionBuilder.cs
- TextSpanModifier.cs
- DataGridViewTextBoxCell.cs
- DataGridCellEditEndingEventArgs.cs
- TransformedBitmap.cs
- ObjectCloneHelper.cs
- MethodResolver.cs
- TableCell.cs
- ImageButton.cs
- PersonalizationDictionary.cs
- WindowsToolbar.cs
- UIElementParagraph.cs
- DocumentViewerConstants.cs
- Padding.cs
- UrlMappingsSection.cs
- FixedTextView.cs
- FontFamily.cs
- ErrorHandlerModule.cs
- ToolStripButton.cs
- WindowsPen.cs
- AncestorChangedEventArgs.cs
- ServiceDesigner.cs
- ActiveXContainer.cs
- ProcessHostServerConfig.cs
- SqlDataSourceCache.cs
- ProfileManager.cs
- OpenTypeCommon.cs
- DefaultSection.cs
- SqlRowUpdatedEvent.cs
- MDIWindowDialog.cs
- Formatter.cs
- IdnMapping.cs
- CheckBox.cs
- Query.cs
- Privilege.cs
- CodeTypeConstructor.cs
- XmlQueryContext.cs
- DefaultHttpHandler.cs
- CreateUserWizardAutoFormat.cs
- EdmProviderManifest.cs
- COM2ICategorizePropertiesHandler.cs
- HttpCookie.cs
- ColorEditor.cs
- Transform3D.cs
- DataGridViewTopRowAccessibleObject.cs
- ObjectPersistData.cs
- PermissionAttributes.cs
- ModifiableIteratorCollection.cs
- _NativeSSPI.cs
- CatalogPart.cs
- NetPipeSection.cs
- VirtualPathProvider.cs
- EpmCustomContentDeSerializer.cs
- GradientStop.cs
- indexingfiltermarshaler.cs
- CriticalHandle.cs
- RadioButtonFlatAdapter.cs
- FormsAuthenticationUser.cs
- WebPartDisplayMode.cs
- XmlEntityReference.cs
- SetStoryboardSpeedRatio.cs
- CompiledQueryCacheEntry.cs
- RightsManagementInformation.cs
- WSSecurityOneDotZeroReceiveSecurityHeader.cs
- ParameterModifier.cs
- ResourceLoader.cs
- ProxyGenerator.cs
- FragmentQuery.cs
- HMACMD5.cs
- KeyValueSerializer.cs
- DbSourceCommand.cs
- HttpResponse.cs
- DataSvcMapFileSerializer.cs
- WebPartDisplayModeCollection.cs
- Triplet.cs
- _SslStream.cs
- EdmComplexPropertyAttribute.cs
- XmlExpressionDumper.cs
- ReaderOutput.cs
- formatter.cs
- SR.cs
- FillRuleValidation.cs
- UpdateTracker.cs
- AddInServer.cs
- CounterSampleCalculator.cs
- ReferenceConverter.cs
- StylusPointPropertyId.cs
- OutputWindow.cs
- Span.cs
- CultureInfoConverter.cs
- MenuCommand.cs
- AsymmetricKeyExchangeFormatter.cs
- TraceSwitch.cs
- StructuralComparisons.cs
- EventLogPropertySelector.cs
- CatalogPartChrome.cs
- CodeConstructor.cs
- MSAANativeProvider.cs
- BinHexEncoder.cs
- ForeignKeyFactory.cs