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
- XmlObjectSerializerContext.cs
- XmlDataDocument.cs
- SqlUdtInfo.cs
- Gdiplus.cs
- PhonemeEventArgs.cs
- DataSetViewSchema.cs
- ApplicationInterop.cs
- FileSystemWatcher.cs
- TransformGroup.cs
- VolatileEnlistmentMultiplexing.cs
- ComponentRenameEvent.cs
- RelatedPropertyManager.cs
- NTAccount.cs
- GiveFeedbackEventArgs.cs
- CacheVirtualItemsEvent.cs
- DummyDataSource.cs
- DetailsViewInsertEventArgs.cs
- FontDriver.cs
- UrlAuthorizationModule.cs
- TextSerializer.cs
- FormView.cs
- PrivacyNoticeBindingElementImporter.cs
- CalendarDataBindingHandler.cs
- HtmlToClrEventProxy.cs
- MenuTracker.cs
- Stroke.cs
- TcpStreams.cs
- PolicyValidationException.cs
- unitconverter.cs
- Policy.cs
- ExceptionUtil.cs
- DbParameterCollectionHelper.cs
- AppDomainManager.cs
- Parameter.cs
- MsmqDiagnostics.cs
- StrokeNode.cs
- DBAsyncResult.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- LocatorBase.cs
- WizardStepBase.cs
- OdbcEnvironmentHandle.cs
- CodePageEncoding.cs
- LiteralTextContainerControlBuilder.cs
- OdbcDataAdapter.cs
- PointConverter.cs
- DataListItem.cs
- SchemaNamespaceManager.cs
- EventDriven.cs
- SurrogateSelector.cs
- ComPlusInstanceProvider.cs
- ActivityTypeResolver.xaml.cs
- ReplyChannelAcceptor.cs
- ComponentFactoryHelpers.cs
- NonVisualControlAttribute.cs
- CorrelationInitializer.cs
- HierarchicalDataBoundControl.cs
- SelectedGridItemChangedEvent.cs
- Size3D.cs
- ScriptResourceAttribute.cs
- XmlWrappingReader.cs
- PolyLineSegment.cs
- OptimizedTemplateContentHelper.cs
- ToolStripDropDownMenu.cs
- ItemsControl.cs
- DocumentPageHost.cs
- CustomErrorCollection.cs
- Speller.cs
- PrintPreviewGraphics.cs
- EntityDataSourceQueryBuilder.cs
- ArrangedElement.cs
- AnnotationAdorner.cs
- FolderLevelBuildProviderCollection.cs
- ResourceReferenceKeyNotFoundException.cs
- BamlLocalizableResource.cs
- BindingNavigator.cs
- InputReportEventArgs.cs
- KeyEvent.cs
- RectangleF.cs
- CustomAttributeSerializer.cs
- MouseBinding.cs
- InlineUIContainer.cs
- StandardBindingOptionalReliableSessionElement.cs
- IdentityReference.cs
- FilterQuery.cs
- ServiceMemoryGates.cs
- MethodImplAttribute.cs
- XamlNamespaceHelper.cs
- CngKeyBlobFormat.cs
- PasswordRecoveryDesigner.cs
- MexBindingBindingCollectionElement.cs
- RootBrowserWindow.cs
- LineServicesRun.cs
- DataGridViewCellValidatingEventArgs.cs
- ScriptMethodAttribute.cs
- SoundPlayerAction.cs
- DiagnosticTrace.cs
- InstanceData.cs
- RelatedPropertyManager.cs
- ParagraphVisual.cs
- AdapterUtil.cs