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
- TypeConverterAttribute.cs
- EncryptedKey.cs
- LiteralControl.cs
- RC2.cs
- OperationContractAttribute.cs
- EventHandlerList.cs
- InstalledVoice.cs
- SelectionEditor.cs
- OleAutBinder.cs
- WebPartConnectionCollection.cs
- EmptyControlCollection.cs
- PerfService.cs
- SQLGuid.cs
- SwitchElementsCollection.cs
- DateTimeFormat.cs
- MethodBody.cs
- Debug.cs
- MailWriter.cs
- ClientEventManager.cs
- SqlDataSourceCommandParser.cs
- ComponentManagerBroker.cs
- Font.cs
- Window.cs
- WebPageTraceListener.cs
- ValidationHelper.cs
- SyndicationFeed.cs
- QueuedDeliveryRequirementsMode.cs
- FormClosedEvent.cs
- ReferenceService.cs
- AttachedPropertyBrowsableAttribute.cs
- LocatorManager.cs
- WebControl.cs
- SHA1CryptoServiceProvider.cs
- WindowsScrollBar.cs
- GeometryConverter.cs
- PrintEvent.cs
- DefaultWorkflowLoaderService.cs
- EntityDataReader.cs
- EntityClassGenerator.cs
- HttpApplicationFactory.cs
- NonBatchDirectoryCompiler.cs
- _KerberosClient.cs
- CriticalHandle.cs
- ResourcesChangeInfo.cs
- Itemizer.cs
- CompositeClientFormatter.cs
- ExternalCalls.cs
- IntSecurity.cs
- SqlVersion.cs
- UriGenerator.cs
- ToolStrip.cs
- AudioFileOut.cs
- IISMapPath.cs
- LiteralLink.cs
- DesigntimeLicenseContext.cs
- TraceEventCache.cs
- UidManager.cs
- OdbcRowUpdatingEvent.cs
- PDBReader.cs
- TransactedBatchContext.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- DeferredBinaryDeserializerExtension.cs
- DataRecord.cs
- ControlDesignerState.cs
- ClientCultureInfo.cs
- DataGridSortCommandEventArgs.cs
- SyntaxCheck.cs
- SafeSecurityHandles.cs
- SR.cs
- ProcessHost.cs
- DBConnection.cs
- DateTimeOffsetConverter.cs
- EdmComplexTypeAttribute.cs
- MutexSecurity.cs
- DomNameTable.cs
- SessionParameter.cs
- DbProviderServices.cs
- WebHttpBindingCollectionElement.cs
- XmlSchemaProviderAttribute.cs
- TextEditorCharacters.cs
- ThicknessAnimation.cs
- InstanceDescriptor.cs
- RangeBase.cs
- Win32.cs
- Bold.cs
- TriggerAction.cs
- WindowsGraphics2.cs
- ProviderSettings.cs
- XmlQueryStaticData.cs
- AnimationClockResource.cs
- TableLayoutStyleCollection.cs
- EdmMember.cs
- DBDataPermissionAttribute.cs
- StringValidatorAttribute.cs
- XmlCharacterData.cs
- SafePEFileHandle.cs
- SqlUdtInfo.cs
- CssClassPropertyAttribute.cs
- ViewStateChangedEventArgs.cs
- ArcSegment.cs