Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / ByteStack.cs / 1305376 / 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
- WebPartTransformerCollection.cs
- DefaultTextStoreTextComposition.cs
- MutexSecurity.cs
- SQLBoolean.cs
- VoiceInfo.cs
- ProgressBarAutomationPeer.cs
- Vector3D.cs
- ConstraintManager.cs
- PlatformCulture.cs
- DataGridViewAutoSizeModeEventArgs.cs
- SpeechRecognitionEngine.cs
- TemplatePartAttribute.cs
- DataGridItem.cs
- AssemblyCollection.cs
- SecurityCriticalDataForSet.cs
- SQLUtility.cs
- SystemThemeKey.cs
- CapiSymmetricAlgorithm.cs
- CriticalFinalizerObject.cs
- VarRemapper.cs
- UriSection.cs
- ToolConsole.cs
- SudsWriter.cs
- DefaultObjectMappingItemCollection.cs
- Button.cs
- NetworkInformationException.cs
- SqlUdtInfo.cs
- ControlPager.cs
- EntryWrittenEventArgs.cs
- WindowsGraphicsWrapper.cs
- Resources.Designer.cs
- SQLDecimal.cs
- SafeNativeMethodsMilCoreApi.cs
- ReflectionUtil.cs
- Int32Rect.cs
- CalendarDay.cs
- TransformValueSerializer.cs
- HorizontalAlignConverter.cs
- ConnectionProviderAttribute.cs
- OdbcParameterCollection.cs
- Publisher.cs
- Serializer.cs
- ResourceDisplayNameAttribute.cs
- SoapIncludeAttribute.cs
- RemoteWebConfigurationHostStream.cs
- SQLInt16.cs
- ResourceDefaultValueAttribute.cs
- ToolboxService.cs
- ServiceManagerHandle.cs
- SqlDataAdapter.cs
- TextBlock.cs
- ResourceDisplayNameAttribute.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- QueryReaderSettings.cs
- BuilderPropertyEntry.cs
- ListViewHitTestInfo.cs
- DataServiceStreamProviderWrapper.cs
- Border.cs
- XslCompiledTransform.cs
- Size3D.cs
- BufferedStream2.cs
- ValueUnavailableException.cs
- ModifierKeysConverter.cs
- ColumnHeader.cs
- initElementDictionary.cs
- LassoHelper.cs
- SocketInformation.cs
- WebPartManager.cs
- mediapermission.cs
- PermissionListSet.cs
- HttpWriter.cs
- ConfigurationStrings.cs
- XpsS0ValidatingLoader.cs
- WhitespaceRule.cs
- ModelMemberCollection.cs
- CompiledELinqQueryState.cs
- DataSysAttribute.cs
- ArrayTypeMismatchException.cs
- WmlMobileTextWriter.cs
- MexTcpBindingElement.cs
- HotSpot.cs
- Literal.cs
- UInt16Converter.cs
- EnvironmentPermission.cs
- DragDropManager.cs
- AdornerLayer.cs
- HandlerBase.cs
- Decimal.cs
- BaseDataListPage.cs
- BatchParser.cs
- AbstractDataSvcMapFileLoader.cs
- HttpCookiesSection.cs
- DrawingVisual.cs
- XpsS0ValidatingLoader.cs
- DecoderFallback.cs
- AppDomain.cs
- XmlDataSource.cs
- AttachedPropertyBrowsableAttribute.cs
- QueryPageSettingsEventArgs.cs
- XsltInput.cs