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
- ProxyHelper.cs
- HttpCacheVaryByContentEncodings.cs
- TerminatorSinks.cs
- BookmarkManager.cs
- TabItemWrapperAutomationPeer.cs
- ListViewCommandEventArgs.cs
- ImageMap.cs
- StrokeCollection2.cs
- HwndSource.cs
- FamilyTypefaceCollection.cs
- UnknownMessageReceivedEventArgs.cs
- ProfileSettings.cs
- MonikerBuilder.cs
- XmlObjectSerializer.cs
- ProfileParameter.cs
- Types.cs
- QueueProcessor.cs
- CodeAttachEventStatement.cs
- HwndSourceParameters.cs
- ServiceHostingEnvironment.cs
- AssociationSetEnd.cs
- ConfigurationManagerHelper.cs
- Rijndael.cs
- Misc.cs
- _PooledStream.cs
- SecurityMode.cs
- QueryActivatableWorkflowsCommand.cs
- HttpRequestCacheValidator.cs
- XmlIterators.cs
- CustomWebEventKey.cs
- CompressEmulationStream.cs
- Int16.cs
- PingReply.cs
- DataException.cs
- PointLightBase.cs
- XPathNavigatorKeyComparer.cs
- EventMappingSettingsCollection.cs
- HashCodeCombiner.cs
- ControlPaint.cs
- ImmutableClientRuntime.cs
- SspiNegotiationTokenProviderState.cs
- XmlEventCache.cs
- TripleDES.cs
- InplaceBitmapMetadataWriter.cs
- Section.cs
- XmlSchemaDatatype.cs
- DataServiceContext.cs
- ThreadWorkerController.cs
- AccessorTable.cs
- SplayTreeNode.cs
- xsdvalidator.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- TableItemPattern.cs
- TrackingConditionCollection.cs
- UnmanagedBitmapWrapper.cs
- XmlSignatureProperties.cs
- ASCIIEncoding.cs
- RC2.cs
- DataSourceBooleanViewSchemaConverter.cs
- Cloud.cs
- MethodToken.cs
- ClientSession.cs
- MediaScriptCommandRoutedEventArgs.cs
- ToolStripSettings.cs
- LinqDataSourceDisposeEventArgs.cs
- DragEventArgs.cs
- ProxyOperationRuntime.cs
- Formatter.cs
- SimpleWebHandlerParser.cs
- WindowsRichEdit.cs
- WindowInteropHelper.cs
- BasicKeyConstraint.cs
- VerticalAlignConverter.cs
- KeyConstraint.cs
- SyndicationItemFormatter.cs
- DocumentationServerProtocol.cs
- xmlfixedPageInfo.cs
- SqlUdtInfo.cs
- PathFigureCollection.cs
- PolicyException.cs
- CompilationRelaxations.cs
- JsonQNameDataContract.cs
- SrgsItemList.cs
- HttpProtocolImporter.cs
- ToolStripManager.cs
- DesignerGeometryHelper.cs
- RotateTransform3D.cs
- VisualBrush.cs
- WebExceptionStatus.cs
- MsmqIntegrationElement.cs
- RequestQueryProcessor.cs
- HostedTcpTransportManager.cs
- EventMemberCodeDomSerializer.cs
- DockEditor.cs
- OperationAbortedException.cs
- WindowsSpinner.cs
- Lazy.cs
- UrlPath.cs
- GlobalProxySelection.cs
- StringResourceManager.cs