Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- XmlSchemaObject.cs
- Type.cs
- LocationReference.cs
- ExtendedProtectionPolicyTypeConverter.cs
- Vector3DCollectionValueSerializer.cs
- UriScheme.cs
- SqlVersion.cs
- MetadataItemEmitter.cs
- RegexCapture.cs
- XmlTextReader.cs
- XmlReflectionImporter.cs
- ActivityMarkupSerializer.cs
- CursorConverter.cs
- WriterOutput.cs
- SqlRecordBuffer.cs
- Timeline.cs
- ObjectDataSource.cs
- InheritanceContextChangedEventManager.cs
- VerificationAttribute.cs
- SqlCacheDependencyDatabaseCollection.cs
- DataGridClipboardHelper.cs
- AddressUtility.cs
- WindowCollection.cs
- Missing.cs
- _SecureChannel.cs
- DataSysAttribute.cs
- TableAdapterManagerHelper.cs
- AvTraceFormat.cs
- DataControlPagerLinkButton.cs
- SerialReceived.cs
- SmtpNtlmAuthenticationModule.cs
- DataColumn.cs
- JsonMessageEncoderFactory.cs
- Base64Stream.cs
- SafeCryptoHandles.cs
- XmlArrayAttribute.cs
- _AutoWebProxyScriptWrapper.cs
- DBPropSet.cs
- CodeIdentifier.cs
- DataGridViewSortCompareEventArgs.cs
- ValidationRule.cs
- CorrelationKey.cs
- InternalBufferOverflowException.cs
- CollectionView.cs
- ProgressBarHighlightConverter.cs
- ValidatorCollection.cs
- FrameworkTextComposition.cs
- DataErrorValidationRule.cs
- ComplexPropertyEntry.cs
- MonthChangedEventArgs.cs
- SqlProfileProvider.cs
- ExtendedProperty.cs
- MimeXmlImporter.cs
- AnimationLayer.cs
- DocumentEventArgs.cs
- DecimalConstantAttribute.cs
- WebServiceParameterData.cs
- ProxyGenerator.cs
- FormsAuthenticationEventArgs.cs
- SqlClientWrapperSmiStreamChars.cs
- OpCopier.cs
- DataGridViewHeaderCell.cs
- Int32Storage.cs
- EventLogEntryCollection.cs
- ScriptReferenceBase.cs
- SyncMethodInvoker.cs
- FormatterConverter.cs
- FutureFactory.cs
- ResourceDisplayNameAttribute.cs
- webeventbuffer.cs
- MemberMaps.cs
- OleAutBinder.cs
- DoubleKeyFrameCollection.cs
- SmtpNtlmAuthenticationModule.cs
- ImagingCache.cs
- SchemaSetCompiler.cs
- VisualBasicReference.cs
- Block.cs
- ObjectNotFoundException.cs
- InstanceCompleteException.cs
- LockCookie.cs
- XmlBufferReader.cs
- HttpCapabilitiesBase.cs
- ConnectionInterfaceCollection.cs
- xdrvalidator.cs
- MembershipPasswordException.cs
- SubMenuStyleCollection.cs
- SocketSettings.cs
- FrameworkElementAutomationPeer.cs
- StylusCaptureWithinProperty.cs
- TemplatedWizardStep.cs
- Quad.cs
- RuleRefElement.cs
- SafeLibraryHandle.cs
- WebPartRestoreVerb.cs
- CopyOnWriteList.cs
- ImageFormatConverter.cs
- SrgsElementFactory.cs
- UrlParameterWriter.cs
- DashStyles.cs