Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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; } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ClientType.cs
- LocatorPart.cs
- ToolStripDropDownButton.cs
- StringUtil.cs
- indexingfiltermarshaler.cs
- NegatedCellConstant.cs
- UnaryExpressionHelper.cs
- WindowManager.cs
- ConnectivityStatus.cs
- TextOnlyOutput.cs
- TableCell.cs
- PieceDirectory.cs
- XmlSchemaInclude.cs
- Parser.cs
- ProvidePropertyAttribute.cs
- TCPClient.cs
- TypeElementCollection.cs
- ScrollPattern.cs
- GreaterThanOrEqual.cs
- OleDbConnectionFactory.cs
- MediaElementAutomationPeer.cs
- HeaderUtility.cs
- AutomationPropertyInfo.cs
- MouseActionValueSerializer.cs
- ProcessProtocolHandler.cs
- SecurityState.cs
- Filter.cs
- HandlerFactoryCache.cs
- DocumentApplicationJournalEntry.cs
- SynthesizerStateChangedEventArgs.cs
- NonVisualControlAttribute.cs
- GridViewColumnHeader.cs
- HotCommands.cs
- Drawing.cs
- ShaderRenderModeValidation.cs
- ClientEventManager.cs
- XmlCountingReader.cs
- GestureRecognizer.cs
- DependencyPropertyConverter.cs
- RSAOAEPKeyExchangeDeformatter.cs
- AssemblyName.cs
- PcmConverter.cs
- XmlDesigner.cs
- IArgumentProvider.cs
- BinaryUtilClasses.cs
- LogRestartAreaEnumerator.cs
- StaticExtensionConverter.cs
- ServiceModelReg.cs
- CoTaskMemHandle.cs
- NameTable.cs
- PersonalizationStateInfoCollection.cs
- SafeSystemMetrics.cs
- AbstractExpressions.cs
- ControlPropertyNameConverter.cs
- LabelEditEvent.cs
- ZeroOpNode.cs
- _ListenerAsyncResult.cs
- ByteConverter.cs
- XamlReader.cs
- SingleSelectRootGridEntry.cs
- TableRow.cs
- CheckBox.cs
- XPathNavigatorKeyComparer.cs
- EventRecord.cs
- MatchingStyle.cs
- BitmapFrameEncode.cs
- TogglePattern.cs
- RecordManager.cs
- XmlDataDocument.cs
- WindowsTokenRoleProvider.cs
- GridViewRow.cs
- WebConfigManager.cs
- CheckStoreFileValidityRequest.cs
- DataSet.cs
- MetabaseServerConfig.cs
- WindowsFormsEditorServiceHelper.cs
- QuadraticBezierSegment.cs
- MethodBuilder.cs
- ClientUtils.cs
- XmlNodeChangedEventArgs.cs
- File.cs
- SqlUserDefinedAggregateAttribute.cs
- EndOfStreamException.cs
- DataSourceXmlAttributeAttribute.cs
- ToolStripRenderEventArgs.cs
- IgnoreSection.cs
- WebCategoryAttribute.cs
- EpmSourcePathSegment.cs
- SqlServer2KCompatibilityAnnotation.cs
- IPHostEntry.cs
- ProcessHost.cs
- RecordBuilder.cs
- EllipticalNodeOperations.cs
- ConfigXmlText.cs
- DiscoveryDocumentSearchPattern.cs
- COM2ExtendedTypeConverter.cs
- ClipboardData.cs
- ReadOnlyHierarchicalDataSource.cs
- XmlQueryCardinality.cs
- PersistenceTypeAttribute.cs