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
- _NativeSSPI.cs
- ScrollItemPattern.cs
- X509Extension.cs
- TextControl.cs
- Boolean.cs
- MimePart.cs
- Annotation.cs
- SortableBindingList.cs
- DataControlButton.cs
- OrderByQueryOptionExpression.cs
- WebControlParameterProxy.cs
- DataGridViewToolTip.cs
- DBConcurrencyException.cs
- Configuration.cs
- UIntPtr.cs
- WebAdminConfigurationHelper.cs
- IconBitmapDecoder.cs
- HMACSHA512.cs
- EventLogPropertySelector.cs
- MatrixTransform.cs
- SafeThemeHandle.cs
- dbenumerator.cs
- SharedStatics.cs
- TypefaceMap.cs
- X509ChainElement.cs
- FormsAuthenticationUser.cs
- DataPager.cs
- CodeNamespaceImportCollection.cs
- ContentPropertyAttribute.cs
- DLinqAssociationProvider.cs
- DuplexSecurityProtocolFactory.cs
- ToolStripDropDownClosingEventArgs.cs
- DataGridViewCell.cs
- FixedTextSelectionProcessor.cs
- SessionStateUtil.cs
- SymbolPair.cs
- HashSet.cs
- _LocalDataStore.cs
- clipboard.cs
- DataListItemCollection.cs
- RowsCopiedEventArgs.cs
- EtwTrace.cs
- BamlVersionHeader.cs
- WriteableBitmap.cs
- ThemeableAttribute.cs
- CodeGotoStatement.cs
- CTreeGenerator.cs
- Variable.cs
- TypeToTreeConverter.cs
- PhonemeEventArgs.cs
- NetTcpSection.cs
- SHA384CryptoServiceProvider.cs
- CharEntityEncoderFallback.cs
- InvalidProgramException.cs
- DefaultWorkflowTransactionService.cs
- SurrogateChar.cs
- ConditionalAttribute.cs
- Grant.cs
- PaintValueEventArgs.cs
- CodeMemberMethod.cs
- CapabilitiesRule.cs
- AdvancedBindingEditor.cs
- PageStatePersister.cs
- HtmlInputSubmit.cs
- WsdlBuildProvider.cs
- Rect3D.cs
- AccessorTable.cs
- SecureUICommand.cs
- EncryptedXml.cs
- Configuration.cs
- FontInfo.cs
- Internal.cs
- _SSPISessionCache.cs
- WmlLabelAdapter.cs
- CommandField.cs
- AccessDataSourceDesigner.cs
- ServiceContractViewControl.cs
- LabelLiteral.cs
- ComProxy.cs
- PseudoWebRequest.cs
- WebServiceResponseDesigner.cs
- HttpStreamMessage.cs
- CanExpandCollapseAllConverter.cs
- StorageRoot.cs
- ToolStripSystemRenderer.cs
- mactripleDES.cs
- MultiBinding.cs
- SignedXml.cs
- ItemCheckEvent.cs
- SchemaAttDef.cs
- EventDescriptorCollection.cs
- EventsTab.cs
- AdornerLayer.cs
- CompilerResults.cs
- SqlDataSourceEnumerator.cs
- FlowDocumentPage.cs
- MailDefinition.cs
- FlowDocumentPage.cs
- GridViewCancelEditEventArgs.cs
- ProjectionCamera.cs