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
- DiscoveryReference.cs
- BrowserCapabilitiesFactoryBase.cs
- DataGridrowEditEndingEventArgs.cs
- Fault.cs
- InputDevice.cs
- InkCanvasAutomationPeer.cs
- TableRowCollection.cs
- SqlDataSourceStatusEventArgs.cs
- Thread.cs
- MetadataArtifactLoader.cs
- FileEnumerator.cs
- PersistenceTypeAttribute.cs
- DbConnectionPoolGroupProviderInfo.cs
- TextRenderingModeValidation.cs
- MenuItemBinding.cs
- Stylus.cs
- HttpHandlerActionCollection.cs
- AbsoluteQuery.cs
- UserControlCodeDomTreeGenerator.cs
- ListViewGroupConverter.cs
- TargetInvocationException.cs
- XmlUtil.cs
- XmlSchemaInferenceException.cs
- WindowsFormsHostAutomationPeer.cs
- OperationAbortedException.cs
- TextMarkerSource.cs
- dtdvalidator.cs
- DistinctQueryOperator.cs
- QilIterator.cs
- FileDialogCustomPlace.cs
- CustomErrorsSectionWrapper.cs
- TargetPerspective.cs
- ToolboxItemFilterAttribute.cs
- TransactionManager.cs
- StateRuntime.cs
- ParsedAttributeCollection.cs
- ScriptManagerProxy.cs
- ColumnPropertiesGroup.cs
- TypeDescriptionProviderAttribute.cs
- CodeThrowExceptionStatement.cs
- InProcStateClientManager.cs
- SoapElementAttribute.cs
- MembershipSection.cs
- AssertHelper.cs
- WindowsGraphicsCacheManager.cs
- SafeRightsManagementQueryHandle.cs
- MailHeaderInfo.cs
- ScriptingWebServicesSectionGroup.cs
- AccessorTable.cs
- FocusTracker.cs
- TimeSpan.cs
- _ConnectStream.cs
- StorageInfo.cs
- GroupDescription.cs
- ChangePasswordDesigner.cs
- CreateUserErrorEventArgs.cs
- Main.cs
- DbProviderServices.cs
- WebPermission.cs
- WebServiceHost.cs
- AddInProcess.cs
- regiisutil.cs
- ClientTarget.cs
- ModelItem.cs
- ButtonAutomationPeer.cs
- BamlResourceContent.cs
- Button.cs
- figurelength.cs
- GenericTypeParameterBuilder.cs
- PagedDataSource.cs
- NamedPipeHostedTransportConfiguration.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- TypeToStringValueConverter.cs
- SystemThemeKey.cs
- QilXmlWriter.cs
- ChtmlSelectionListAdapter.cs
- MultiView.cs
- WindowsGraphics2.cs
- HtmlShim.cs
- ClientScriptManager.cs
- SignatureGenerator.cs
- DataServiceClientException.cs
- PathNode.cs
- ExeConfigurationFileMap.cs
- DataStreamFromComStream.cs
- FormatSettings.cs
- SocketPermission.cs
- Math.cs
- ColorMap.cs
- XPathChildIterator.cs
- DbConvert.cs
- CurrentTimeZone.cs
- InheritanceContextChangedEventManager.cs
- DateTimeConverter.cs
- ReferentialConstraint.cs
- WebErrorHandler.cs
- AssociationSetMetadata.cs
- SqlNotificationEventArgs.cs
- SystemException.cs
- ContentPosition.cs