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
- DrawingBrush.cs
- DataBindingCollection.cs
- SqlConnectionPoolGroupProviderInfo.cs
- ClientSettings.cs
- XmlChildNodes.cs
- PermissionListSet.cs
- QueueTransferProtocol.cs
- CapabilitiesRule.cs
- CodeNamespaceCollection.cs
- _NestedMultipleAsyncResult.cs
- ToolStripLabel.cs
- GridViewUpdatedEventArgs.cs
- FreezableOperations.cs
- RegexMatch.cs
- HwndHostAutomationPeer.cs
- Size3D.cs
- StandardCommands.cs
- FlowDocumentReaderAutomationPeer.cs
- x509store.cs
- ArrangedElement.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- SqlDataSourceQueryEditor.cs
- XsdBuildProvider.cs
- ServiceModelConfigurationSection.cs
- RegistryKey.cs
- ResumeStoryboard.cs
- Crc32Helper.cs
- OdbcStatementHandle.cs
- ZipIOExtraFieldElement.cs
- DataSourceDesigner.cs
- DataSourceView.cs
- RequestDescription.cs
- RegexCaptureCollection.cs
- Label.cs
- Axis.cs
- ImageIndexConverter.cs
- SqlDataRecord.cs
- InputScopeNameConverter.cs
- HostProtectionPermission.cs
- XPathExpr.cs
- XslCompiledTransform.cs
- UshortList2.cs
- DockingAttribute.cs
- VScrollProperties.cs
- NameSpaceEvent.cs
- TextLineBreak.cs
- DiscreteKeyFrames.cs
- NamedElement.cs
- SendingRequestEventArgs.cs
- ConnectionStringsExpressionBuilder.cs
- Hex.cs
- XmlIgnoreAttribute.cs
- Trigger.cs
- BinaryReader.cs
- XPathChildIterator.cs
- BuiltInPermissionSets.cs
- IncrementalReadDecoders.cs
- SystemResources.cs
- ComplexPropertyEntry.cs
- OperationParameterInfoCollection.cs
- CanonicalFormWriter.cs
- ParentQuery.cs
- SerializerDescriptor.cs
- OuterGlowBitmapEffect.cs
- COM2TypeInfoProcessor.cs
- FileClassifier.cs
- SafeSecurityHandles.cs
- ToolBarButton.cs
- BrowserCapabilitiesFactoryBase.cs
- Nullable.cs
- WebPartDeleteVerb.cs
- CompositionTarget.cs
- DataGridViewComboBoxEditingControl.cs
- ExpressionPrefixAttribute.cs
- FullTextState.cs
- IRCollection.cs
- AlternateViewCollection.cs
- DbConnectionOptions.cs
- InvokeBase.cs
- BindingWorker.cs
- prefixendpointaddressmessagefilter.cs
- CopyAction.cs
- ClientSettingsStore.cs
- CroppedBitmap.cs
- UpdateManifestForBrowserApplication.cs
- _Connection.cs
- NumberFunctions.cs
- TagPrefixAttribute.cs
- RemoteWebConfigurationHostServer.cs
- ResXBuildProvider.cs
- RecognitionResult.cs
- NavigationCommands.cs
- Visual3D.cs
- WindowsEditBox.cs
- StructuredTypeEmitter.cs
- AssociatedControlConverter.cs
- ByteStack.cs
- Win32Exception.cs
- ServiceDescriptionImporter.cs
- BoundColumn.cs