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
- DecimalSumAggregationOperator.cs
- TaskFileService.cs
- FileLoadException.cs
- SiteMapNodeItem.cs
- UnsafeNativeMethods.cs
- EventLogPropertySelector.cs
- CatalogPartChrome.cs
- HttpCapabilitiesBase.cs
- HyperlinkAutomationPeer.cs
- LinqDataSourceStatusEventArgs.cs
- SHA1Managed.cs
- NamespaceCollection.cs
- SetUserPreferenceRequest.cs
- XmlValidatingReaderImpl.cs
- InputBuffer.cs
- DropDownList.cs
- FamilyTypefaceCollection.cs
- TextStore.cs
- IfJoinedCondition.cs
- RegexTypeEditor.cs
- HandlerBase.cs
- DesignerOptionService.cs
- DBAsyncResult.cs
- FormatterServices.cs
- ParsedAttributeCollection.cs
- PropertyReference.cs
- DataSourceXmlSerializationAttribute.cs
- TickBar.cs
- WorkflowExecutor.cs
- ResourceDescriptionAttribute.cs
- MatrixTransform.cs
- DataGridViewRow.cs
- WebPartActionVerb.cs
- CodeIdentifier.cs
- TemplateField.cs
- PolicyStatement.cs
- VBIdentifierTrimConverter.cs
- EventManager.cs
- NodeFunctions.cs
- EditingCommands.cs
- ComboBoxAutomationPeer.cs
- HMACRIPEMD160.cs
- FullTextBreakpoint.cs
- XPathBinder.cs
- RoutedUICommand.cs
- Delay.cs
- Crypto.cs
- BinaryExpression.cs
- DateTimeConverter2.cs
- Int64KeyFrameCollection.cs
- ComplexPropertyEntry.cs
- RemotingAttributes.cs
- SqlTypeSystemProvider.cs
- DataBoundLiteralControl.cs
- OSFeature.cs
- RtfToXamlReader.cs
- SafeArrayRankMismatchException.cs
- MimeObjectFactory.cs
- ViewKeyConstraint.cs
- ZoomPercentageConverter.cs
- Soap12ProtocolImporter.cs
- Adorner.cs
- ScalarConstant.cs
- DataGridAutoFormat.cs
- OutputCacheProfileCollection.cs
- Bezier.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- NativeMethodsCLR.cs
- CultureTableRecord.cs
- FormParameter.cs
- SqlDelegatedTransaction.cs
- SchemaManager.cs
- SimpleType.cs
- WebOperationContext.cs
- RegexCharClass.cs
- EventRoute.cs
- XmlSchemaAll.cs
- XPathAxisIterator.cs
- WindowCollection.cs
- ToolboxItem.cs
- _ConnectionGroup.cs
- Package.cs
- RsaEndpointIdentity.cs
- LookupBindingPropertiesAttribute.cs
- HtmlProps.cs
- CrossSiteScriptingValidation.cs
- SelectionWordBreaker.cs
- ScrollBar.cs
- TerminateWorkflow.cs
- SweepDirectionValidation.cs
- ResourcePool.cs
- Italic.cs
- DataFieldConverter.cs
- unsafeIndexingFilterStream.cs
- Baml6Assembly.cs
- InputReferenceExpression.cs
- DateTimeConstantAttribute.cs
- WindowsListViewGroupSubsetLink.cs
- ToolTip.cs
- SamlAction.cs