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
- AppDomainAttributes.cs
- InputBindingCollection.cs
- ToolboxItem.cs
- SecurityDocument.cs
- XmlSiteMapProvider.cs
- ClusterSafeNativeMethods.cs
- ObjectComplexPropertyMapping.cs
- ReadOnlyDataSource.cs
- ToolStripDropDownClosedEventArgs.cs
- UIAgentAsyncBeginRequest.cs
- SafeCryptoHandles.cs
- ActivationArguments.cs
- KeyMatchBuilder.cs
- ContentElementAutomationPeer.cs
- NamespaceImport.cs
- ServiceDebugElement.cs
- WCFServiceClientProxyGenerator.cs
- GetTokenRequest.cs
- ProfileParameter.cs
- CompilationLock.cs
- WebPartCatalogCloseVerb.cs
- SharedStatics.cs
- HandlerFactoryCache.cs
- FieldNameLookup.cs
- TextDecorationUnitValidation.cs
- AndCondition.cs
- _ConnectStream.cs
- ExceptionHandler.cs
- SystemGatewayIPAddressInformation.cs
- TabRenderer.cs
- DataRowView.cs
- SymbolResolver.cs
- OleDbStruct.cs
- GuidelineSet.cs
- SqlWebEventProvider.cs
- IndexingContentUnit.cs
- PageClientProxyGenerator.cs
- Journal.cs
- WpfGeneratedKnownProperties.cs
- LoadedOrUnloadedOperation.cs
- DrawToolTipEventArgs.cs
- WebPartConnectionsConfigureVerb.cs
- CompilationLock.cs
- ItemsControl.cs
- DocumentPageTextView.cs
- ConfigXmlSignificantWhitespace.cs
- SqlTypeConverter.cs
- Int32Collection.cs
- AuthenticationConfig.cs
- PermissionSetTriple.cs
- InstanceData.cs
- NegationPusher.cs
- SafeFindHandle.cs
- ListManagerBindingsCollection.cs
- XmlConvert.cs
- DetailsViewPagerRow.cs
- SmtpReplyReaderFactory.cs
- Line.cs
- TreeWalker.cs
- _HTTPDateParse.cs
- WindowsTab.cs
- ProfileModule.cs
- OuterGlowBitmapEffect.cs
- cookieexception.cs
- List.cs
- ComponentResourceKeyConverter.cs
- XmlSchemaExternal.cs
- RenderContext.cs
- SelectionRangeConverter.cs
- XmlParserContext.cs
- Cell.cs
- ZipFileInfoCollection.cs
- NavigationExpr.cs
- ReflectPropertyDescriptor.cs
- Size3DValueSerializer.cs
- OdbcConnectionStringbuilder.cs
- Int16.cs
- Constraint.cs
- DefaultAsyncDataDispatcher.cs
- SystemTcpStatistics.cs
- WindowsSlider.cs
- GreaterThan.cs
- ParallelTimeline.cs
- DragDrop.cs
- Deserializer.cs
- DetailsViewInsertedEventArgs.cs
- StreamInfo.cs
- TreeView.cs
- WebPartPersonalization.cs
- WebPartConnectionsConfigureVerb.cs
- KeyValueInternalCollection.cs
- DataKey.cs
- SystemTcpStatistics.cs
- SwitchLevelAttribute.cs
- QuadraticBezierSegment.cs
- SHA1CryptoServiceProvider.cs
- ClientSettingsSection.cs
- TileBrush.cs
- ProxyWebPart.cs
- Rect3D.cs