Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / UnSafeCharBuffer.cs / 1 / UnSafeCharBuffer.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: UnSafeBuffer ** ** Purpose: A class to detect incorrect usage of UnSafeBuffer ** ** ===========================================================*/ namespace System { using System.Diagnostics; unsafe internal struct UnSafeCharBuffer{ char * m_buffer; int m_totalSize; int m_length; public UnSafeCharBuffer( char *buffer, int bufferSize) { BCLDebug.Assert( buffer != null, "buffer pointer can't be null." ); BCLDebug.Assert( bufferSize >= 0, "buffer size can't be negative." ); m_buffer = buffer; m_totalSize = bufferSize; m_length = 0; } public void AppendString(string stringToAppend) { if( String.IsNullOrEmpty( stringToAppend ) ) { return; } if ( (m_totalSize - m_length) < stringToAppend.Length ) { throw new IndexOutOfRangeException(); } fixed( char* pointerToString = stringToAppend ) { Buffer.memcpyimpl( (byte *) pointerToString, (byte*) (m_buffer + m_length), stringToAppend.Length * sizeof(char)); } m_length += stringToAppend.Length; BCLDebug.Assert(m_length <= m_totalSize, "Buffer has been overflowed!"); } public int Length { get { return m_length; } } } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObfuscationAttribute.cs
- TextRangeProviderWrapper.cs
- SoapHeader.cs
- WindowsListViewGroup.cs
- HttpRequestCacheValidator.cs
- ElapsedEventArgs.cs
- SafeUserTokenHandle.cs
- CreateUserWizardDesigner.cs
- DrawingContextWalker.cs
- StructuredTypeInfo.cs
- CommandHelpers.cs
- DocumentOrderQuery.cs
- AutomationEvent.cs
- BitmapVisualManager.cs
- XmlText.cs
- HttpBrowserCapabilitiesWrapper.cs
- IItemProperties.cs
- Grid.cs
- AssertSection.cs
- Int32KeyFrameCollection.cs
- Binding.cs
- TemplateBindingExpression.cs
- TableCell.cs
- PrePrepareMethodAttribute.cs
- IconBitmapDecoder.cs
- GridErrorDlg.cs
- MetadataArtifactLoaderFile.cs
- ErrorWebPart.cs
- CodeMethodInvokeExpression.cs
- ServicePoint.cs
- XomlCompilerError.cs
- CodeExpressionCollection.cs
- HandlerMappingMemo.cs
- SqlParameter.cs
- OptimizerPatterns.cs
- XhtmlTextWriter.cs
- DesignTableCollection.cs
- WindowsScrollBar.cs
- TypeInfo.cs
- TrackingDataItemValue.cs
- AppliesToBehaviorDecisionTable.cs
- OracleBoolean.cs
- WebDisplayNameAttribute.cs
- DataGridState.cs
- AmbientValueAttribute.cs
- PkcsMisc.cs
- SerializationHelper.cs
- PublisherMembershipCondition.cs
- PersonalizationProviderCollection.cs
- SiteMapProvider.cs
- ConstNode.cs
- Nodes.cs
- RegistryKey.cs
- SoapExtension.cs
- FixedSOMFixedBlock.cs
- TextServicesDisplayAttribute.cs
- LassoSelectionBehavior.cs
- MatrixTransform3D.cs
- AnonymousIdentificationSection.cs
- WebPartConnectionsCancelEventArgs.cs
- SQLInt16Storage.cs
- securitycriticaldataformultiplegetandset.cs
- Point.cs
- SystemUdpStatistics.cs
- ProgressiveCrcCalculatingStream.cs
- GeometryGroup.cs
- ListSourceHelper.cs
- MdbDataFileEditor.cs
- WebPartCancelEventArgs.cs
- VarRemapper.cs
- XmlSchemaChoice.cs
- SystemWebSectionGroup.cs
- ArrayExtension.cs
- GlyphInfoList.cs
- GlyphShapingProperties.cs
- XmlSchemaComplexContentRestriction.cs
- BitmapFrameEncode.cs
- FrameworkTextComposition.cs
- ListSourceHelper.cs
- HttpListenerElement.cs
- XmlDataSourceView.cs
- DSASignatureFormatter.cs
- TypeCollectionPropertyEditor.cs
- TemplatedWizardStep.cs
- ConfigurationManagerInternal.cs
- CustomTypeDescriptor.cs
- RightsManagementPermission.cs
- Cursor.cs
- IgnoreSectionHandler.cs
- ActiveXMessageFormatter.cs
- DataGridAddNewRow.cs
- Trace.cs
- recordstate.cs
- ScaleTransform.cs
- ColumnWidthChangingEvent.cs
- ErrorsHelper.cs
- SerializationAttributes.cs
- IntellisenseTextBox.designer.cs
- COM2ICategorizePropertiesHandler.cs
- UidManager.cs