Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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; } } } } // 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
- HttpInputStream.cs
- UriSectionReader.cs
- RegistryPermission.cs
- shaperfactory.cs
- JapaneseCalendar.cs
- COMException.cs
- MethodCallTranslator.cs
- EdmConstants.cs
- TransactionOptions.cs
- HealthMonitoringSection.cs
- RoutedEvent.cs
- ContextMenu.cs
- FormatterServices.cs
- OleDbPropertySetGuid.cs
- Socket.cs
- ChangePassword.cs
- DBConnectionString.cs
- Types.cs
- XamlBuildTaskServices.cs
- Line.cs
- RegexInterpreter.cs
- FixedTextBuilder.cs
- StopRoutingHandler.cs
- XPathArrayIterator.cs
- Binding.cs
- DesignTableCollection.cs
- EventWaitHandleSecurity.cs
- DataColumnCollection.cs
- ConnectionManagementSection.cs
- ZoneButton.cs
- TabControl.cs
- Roles.cs
- TextEditorSelection.cs
- XmlSchemaRedefine.cs
- SqlBuffer.cs
- SecurityDescriptor.cs
- VideoDrawing.cs
- NameValuePermission.cs
- HttpPostLocalhostServerProtocol.cs
- Scene3D.cs
- TabControlEvent.cs
- EndpointIdentityConverter.cs
- PointConverter.cs
- TreeViewBindingsEditor.cs
- XmlStreamStore.cs
- LabelDesigner.cs
- GeneratedCodeAttribute.cs
- CfgSemanticTag.cs
- SqlCommandSet.cs
- querybuilder.cs
- FullTrustAssembly.cs
- AcceleratedTokenProviderState.cs
- SymLanguageVendor.cs
- MemoryPressure.cs
- RectangleGeometry.cs
- HttpWebRequestElement.cs
- DeviceContext.cs
- TypeBinaryExpression.cs
- TransformedBitmap.cs
- AbstractDataSvcMapFileLoader.cs
- ValidationHelper.cs
- TypeBuilderInstantiation.cs
- Grid.cs
- TextElementEnumerator.cs
- XmlEntity.cs
- HashJoinQueryOperatorEnumerator.cs
- SmiEventSink_Default.cs
- SmiRequestExecutor.cs
- Tuple.cs
- RenderOptions.cs
- OrderPreservingSpoolingTask.cs
- ToolStripGrip.cs
- SqlDataSourceCache.cs
- ItemChangedEventArgs.cs
- ConsumerConnectionPoint.cs
- OneOf.cs
- CreateUserWizard.cs
- DocumentsTrace.cs
- GridItemProviderWrapper.cs
- ScriptReferenceEventArgs.cs
- OTFRasterizer.cs
- SudsCommon.cs
- Compiler.cs
- HealthMonitoringSection.cs
- SystemIPGlobalProperties.cs
- SortDescription.cs
- SimpleApplicationHost.cs
- _LocalDataStore.cs
- CollectionBuilder.cs
- AppliedDeviceFiltersDialog.cs
- ListViewItem.cs
- EntityWithChangeTrackerStrategy.cs
- pingexception.cs
- MatrixKeyFrameCollection.cs
- DropDownHolder.cs
- Triplet.cs
- StylusCaptureWithinProperty.cs
- TransactedBatchingBehavior.cs
- KeySpline.cs
- PingReply.cs