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
- Asn1Utilities.cs
- HttpPostedFile.cs
- ToolStripSeparator.cs
- PersonalizationAdministration.cs
- RenamedEventArgs.cs
- XmlSchemaCompilationSettings.cs
- CompilerState.cs
- TextCompositionManager.cs
- HtmlInputButton.cs
- XmlArrayAttribute.cs
- SecurityElement.cs
- Conditional.cs
- AutomationElement.cs
- IndicCharClassifier.cs
- XmlDataSourceNodeDescriptor.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- ToolStripRenderer.cs
- RepeaterItemCollection.cs
- IgnoreSectionHandler.cs
- listitem.cs
- ColorPalette.cs
- StateBag.cs
- _ListenerResponseStream.cs
- ToolStripProgressBar.cs
- WebBrowserSiteBase.cs
- LineServicesCallbacks.cs
- BufferedWebEventProvider.cs
- DataView.cs
- PrintEvent.cs
- FontCollection.cs
- Pen.cs
- InfoCardArgumentException.cs
- PersonalizationProviderCollection.cs
- EpmContentDeSerializer.cs
- CustomAttribute.cs
- ThemeDictionaryExtension.cs
- WebExceptionStatus.cs
- HMACMD5.cs
- FreezableDefaultValueFactory.cs
- TreeWalkHelper.cs
- AspNetSynchronizationContext.cs
- ButtonStandardAdapter.cs
- WpfPayload.cs
- DriveInfo.cs
- Tokenizer.cs
- TableItemStyle.cs
- ExtenderHelpers.cs
- UnsafeNativeMethodsTablet.cs
- ToolStripDropDownItemDesigner.cs
- xmlsaver.cs
- SmtpFailedRecipientsException.cs
- DateTimeConverter.cs
- ConnectionPointConverter.cs
- EventEntry.cs
- OptimizerPatterns.cs
- AssemblyUtil.cs
- CodeSnippetCompileUnit.cs
- MeasureItemEvent.cs
- XmlSchemaInclude.cs
- HTTPNotFoundHandler.cs
- MinimizableAttributeTypeConverter.cs
- HostProtectionPermission.cs
- CodeTypeDelegate.cs
- TTSVoice.cs
- TransformerConfigurationWizardBase.cs
- ApplicationCommands.cs
- LicFileLicenseProvider.cs
- AttributeEmitter.cs
- SqlConnectionFactory.cs
- LinqDataSourceDisposeEventArgs.cs
- QueryableDataSource.cs
- Internal.cs
- RoutedUICommand.cs
- BoundField.cs
- AudioFormatConverter.cs
- diagnosticsswitches.cs
- base64Transforms.cs
- WindowsSolidBrush.cs
- MetadataException.cs
- SizeAnimationClockResource.cs
- ProtocolImporter.cs
- Separator.cs
- VideoDrawing.cs
- BamlTreeMap.cs
- SqlResolver.cs
- ThousandthOfEmRealDoubles.cs
- WebSysDescriptionAttribute.cs
- TextEditorTables.cs
- DataGridGeneralPage.cs
- BindingMAnagerBase.cs
- Operand.cs
- HttpPostLocalhostServerProtocol.cs
- DecimalConverter.cs
- DateTimeValueSerializerContext.cs
- Number.cs
- ProviderException.cs
- RootAction.cs
- ReadOnlyHierarchicalDataSource.cs
- RemotingException.cs
- DataPagerFieldCommandEventArgs.cs