Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- SystemEvents.cs
- DecoderNLS.cs
- SQLByteStorage.cs
- SelectionPatternIdentifiers.cs
- ZoomPercentageConverter.cs
- ScriptResourceMapping.cs
- TcpClientCredentialType.cs
- Transform3DGroup.cs
- TagMapCollection.cs
- ProfileServiceManager.cs
- UnauthorizedAccessException.cs
- IdentitySection.cs
- ReadOnlyCollectionBuilder.cs
- RefExpr.cs
- ParallelDesigner.cs
- SqlClientMetaDataCollectionNames.cs
- Variant.cs
- PropertyToken.cs
- ImageInfo.cs
- ToolBarTray.cs
- ProfileGroupSettingsCollection.cs
- Membership.cs
- ActivationServices.cs
- ConstraintStruct.cs
- TextDecoration.cs
- SplitterCancelEvent.cs
- GlyphCache.cs
- ThrowHelper.cs
- TargetInvocationException.cs
- InvokeBinder.cs
- PartitionResolver.cs
- EditingMode.cs
- InstalledFontCollection.cs
- AsymmetricAlgorithm.cs
- QilBinary.cs
- ISAPIApplicationHost.cs
- CachedFontFace.cs
- ListCommandEventArgs.cs
- IssuedTokenParametersElement.cs
- ParameterRefs.cs
- DataGridViewDataConnection.cs
- InvokeWebService.cs
- BaseTransportHeaders.cs
- SiteMapPath.cs
- SQLUtility.cs
- EncryptedReference.cs
- TagPrefixInfo.cs
- TraceHandlerErrorFormatter.cs
- ClientBuildManagerCallback.cs
- Viewport2DVisual3D.cs
- Root.cs
- BitStack.cs
- IndexedEnumerable.cs
- ExpressionConverter.cs
- FileVersion.cs
- GZipStream.cs
- CustomCategoryAttribute.cs
- PageAsyncTaskManager.cs
- ObfuscationAttribute.cs
- TypeDescriptionProvider.cs
- listviewsubitemcollectioneditor.cs
- TagMapInfo.cs
- RsaKeyIdentifierClause.cs
- TimelineGroup.cs
- ParsedAttributeCollection.cs
- NetMsmqBindingCollectionElement.cs
- CheckBoxField.cs
- DesignerActionList.cs
- PixelShader.cs
- ManifestResourceInfo.cs
- PropertyEntry.cs
- OleDbConnection.cs
- MapPathBasedVirtualPathProvider.cs
- ConfigXmlComment.cs
- CheckableControlBaseAdapter.cs
- AuthenticationService.cs
- ColorAnimationUsingKeyFrames.cs
- MessagingDescriptionAttribute.cs
- Point3DAnimation.cs
- SlipBehavior.cs
- FormsAuthenticationUserCollection.cs
- RegexGroupCollection.cs
- ServicesUtilities.cs
- ExtensionMethods.cs
- ObjectSpanRewriter.cs
- ServiceNameElementCollection.cs
- WinFormsSpinner.cs
- XappLauncher.cs
- TraceInternal.cs
- HasCopySemanticsAttribute.cs
- SeverityFilter.cs
- Misc.cs
- TextProperties.cs
- CodeExporter.cs
- DataRelationCollection.cs
- StylusPointCollection.cs
- RemoteAsymmetricSignatureFormatter.cs
- CompressStream.cs
- ProcessHostFactoryHelper.cs
- RuntimeHelpers.cs