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
- ItemCollection.cs
- Condition.cs
- ComPlusTraceRecord.cs
- PersonalizationState.cs
- RequestQueue.cs
- ResourceReader.cs
- WorkflowEventArgs.cs
- PropertyGeneratedEventArgs.cs
- DrawingAttributesDefaultValueFactory.cs
- ServiceOperationListItem.cs
- NetworkStream.cs
- NavigationProperty.cs
- EpmContentDeSerializerBase.cs
- AdCreatedEventArgs.cs
- InheritanceContextChangedEventManager.cs
- ProcessModelSection.cs
- WorkflowApplicationUnhandledExceptionEventArgs.cs
- ToolStripLabel.cs
- PersonalizationEntry.cs
- DataBindingCollection.cs
- WorkflowApplicationCompletedException.cs
- __Filters.cs
- TextServicesCompartmentEventSink.cs
- ColumnProvider.cs
- DataBindingCollection.cs
- StylusPointPropertyInfoDefaults.cs
- EntityViewGenerationConstants.cs
- RoleExceptions.cs
- DesignTimeParseData.cs
- WindowsClientCredential.cs
- InstallerTypeAttribute.cs
- _AutoWebProxyScriptEngine.cs
- SystemIcons.cs
- PropertyConverter.cs
- DrawingBrush.cs
- PersonalizationProviderCollection.cs
- OutOfMemoryException.cs
- ExtractCollection.cs
- ButtonBaseAutomationPeer.cs
- GridViewRowCollection.cs
- DataGridViewMethods.cs
- XsltContext.cs
- FlowDocumentFormatter.cs
- PauseStoryboard.cs
- MaterialGroup.cs
- ResourceDictionaryCollection.cs
- DocumentViewerAutomationPeer.cs
- HuffCodec.cs
- HttpCachePolicyElement.cs
- CodeMemberEvent.cs
- SortedList.cs
- DataGridViewDataErrorEventArgs.cs
- TargetControlTypeAttribute.cs
- Attributes.cs
- RuleValidation.cs
- IgnoreFileBuildProvider.cs
- KnownBoxes.cs
- TypeElement.cs
- DataGridViewCellCancelEventArgs.cs
- DependencyPropertyAttribute.cs
- TdsParserStateObject.cs
- TransformerConfigurationWizardBase.cs
- JsonDeserializer.cs
- DetailsViewRowCollection.cs
- ListManagerBindingsCollection.cs
- MailSettingsSection.cs
- DefaultPropertyAttribute.cs
- ObjectListCommand.cs
- BinaryWriter.cs
- X509Certificate2.cs
- TextSegment.cs
- XmlDataSourceView.cs
- DataGridView.cs
- KerberosSecurityTokenProvider.cs
- Selection.cs
- XmlValidatingReaderImpl.cs
- ToolboxItemImageConverter.cs
- Bits.cs
- MessageEventSubscriptionService.cs
- BooleanKeyFrameCollection.cs
- CodeDomConfigurationHandler.cs
- SafeFileHandle.cs
- EntityDataSourceChangingEventArgs.cs
- MenuItemBinding.cs
- ContentElement.cs
- MessageBox.cs
- UndoEngine.cs
- AlphaSortedEnumConverter.cs
- Utils.cs
- HierarchicalDataBoundControlAdapter.cs
- DropDownButton.cs
- BrowserCapabilitiesFactory.cs
- MailDefinition.cs
- ObjectQuery.cs
- MenuRendererClassic.cs
- FontClient.cs
- ScriptReference.cs
- XamlWrapperReaders.cs
- RandomNumberGenerator.cs
- CompareValidator.cs