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
- PingReply.cs
- LazyTextWriterCreator.cs
- NullableConverter.cs
- TabControlCancelEvent.cs
- PartitionerStatic.cs
- DataColumnMapping.cs
- XmlObjectSerializerReadContextComplexJson.cs
- LoginCancelEventArgs.cs
- KeyConstraint.cs
- ByteConverter.cs
- AsymmetricSignatureDeformatter.cs
- MetadataArtifactLoaderComposite.cs
- TransformFinalBlockRequest.cs
- SineEase.cs
- HMACMD5.cs
- DataServiceContext.cs
- Converter.cs
- BaseDataList.cs
- CustomBindingElementCollection.cs
- ResourcesChangeInfo.cs
- ResourceIDHelper.cs
- SecurityElement.cs
- ZipIOExtraField.cs
- TrackingMemoryStreamFactory.cs
- Typography.cs
- SR.cs
- XmlComment.cs
- UnicodeEncoding.cs
- CodeTypeReferenceCollection.cs
- PackageDigitalSignature.cs
- TableRowCollection.cs
- FloaterBaseParaClient.cs
- ObjectQuery_EntitySqlExtensions.cs
- TimeZone.cs
- IgnoreSectionHandler.cs
- AnimationException.cs
- AddIn.cs
- SqlBooleanMismatchVisitor.cs
- DbProviderManifest.cs
- Preprocessor.cs
- AlphabetConverter.cs
- Win32Exception.cs
- NotSupportedException.cs
- WorkflowDataContext.cs
- Stack.cs
- SchemaDeclBase.cs
- CaseStatement.cs
- ResourceDescriptionAttribute.cs
- AndCondition.cs
- StructuralCache.cs
- ActivityMarkupSerializationProvider.cs
- RegexRunner.cs
- UnsafeNativeMethods.cs
- DoubleLink.cs
- WebPartCancelEventArgs.cs
- GenericRootAutomationPeer.cs
- MasterPageParser.cs
- DefaultObjectMappingItemCollection.cs
- StyleReferenceConverter.cs
- VerificationException.cs
- ResXFileRef.cs
- PromptBuilder.cs
- SplitContainerDesigner.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- HighContrastHelper.cs
- BaseCodePageEncoding.cs
- PropertyTab.cs
- SecurityException.cs
- KeyValueConfigurationCollection.cs
- RectKeyFrameCollection.cs
- ProtocolElement.cs
- SaveFileDialog.cs
- DocumentViewerConstants.cs
- SafeCryptContextHandle.cs
- ObjectDataSourceDisposingEventArgs.cs
- COM2Enum.cs
- TextEditorTables.cs
- InvokePattern.cs
- TypeTypeConverter.cs
- Matrix3DValueSerializer.cs
- LinqDataSourceContextEventArgs.cs
- ReadOnlyObservableCollection.cs
- SafeNativeMethods.cs
- PointCollectionValueSerializer.cs
- TrackingValidationObjectDictionary.cs
- CollectionDataContractAttribute.cs
- CompilerCollection.cs
- InertiaTranslationBehavior.cs
- XmlC14NWriter.cs
- HostProtectionPermission.cs
- PageCatalogPartDesigner.cs
- DataTemplateSelector.cs
- OdbcTransaction.cs
- MemoryPressure.cs
- XNodeNavigator.cs
- StringPropertyBuilder.cs
- ClockGroup.cs
- RectValueSerializer.cs
- _ConnectStream.cs
- DataBoundLiteralControl.cs