Code:
/ DotNET / DotNET / 8.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
- SafeBitVector32.cs
- InputElement.cs
- AdapterUtil.cs
- ConsoleCancelEventArgs.cs
- CodeTypeOfExpression.cs
- VariableBinder.cs
- SymmetricKeyWrap.cs
- Material.cs
- RequestCachePolicy.cs
- EntityTypeBase.cs
- Size3D.cs
- SmtpSection.cs
- WebSysDisplayNameAttribute.cs
- CollectionConverter.cs
- mansign.cs
- NumericUpDownAccelerationCollection.cs
- MimeMultiPart.cs
- keycontainerpermission.cs
- ConsoleCancelEventArgs.cs
- PermissionSetEnumerator.cs
- WinCategoryAttribute.cs
- DrawingState.cs
- Emitter.cs
- ParseElementCollection.cs
- DownloadProgressEventArgs.cs
- ColorConverter.cs
- FieldInfo.cs
- Clipboard.cs
- CheckoutException.cs
- XPathPatternBuilder.cs
- CellParaClient.cs
- CodeExporter.cs
- handlecollector.cs
- ContentPresenter.cs
- BufferedWebEventProvider.cs
- EventProxy.cs
- WebSysDescriptionAttribute.cs
- ConnectivityStatus.cs
- TableCell.cs
- WindowsIPAddress.cs
- ClientScriptItemCollection.cs
- TimerTable.cs
- ActivityIdHeader.cs
- InvalidProgramException.cs
- UIElementAutomationPeer.cs
- IndexOutOfRangeException.cs
- ListItemCollection.cs
- storepermissionattribute.cs
- ControllableStoryboardAction.cs
- ToolStripSystemRenderer.cs
- AsyncResult.cs
- WebProxyScriptElement.cs
- WebServiceHandler.cs
- SectionUpdates.cs
- ErrorWebPart.cs
- QueryComponents.cs
- SeparatorAutomationPeer.cs
- ContainerVisual.cs
- SQLConvert.cs
- UpdateRecord.cs
- ObjectCloneHelper.cs
- ResourceContainer.cs
- cookiecollection.cs
- BoundColumn.cs
- WebResponse.cs
- xmlformatgeneratorstatics.cs
- RuntimeConfigLKG.cs
- IISUnsafeMethods.cs
- ByteStorage.cs
- CodeSubDirectoriesCollection.cs
- Section.cs
- SiteMap.cs
- GrammarBuilderDictation.cs
- CodeCompiler.cs
- QilDataSource.cs
- LinqDataSourceStatusEventArgs.cs
- EntityParameter.cs
- XmlEntityReference.cs
- HtmlContainerControl.cs
- CellConstantDomain.cs
- TreeNodeStyleCollection.cs
- ToolStripDropDownItem.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- StatusBarDrawItemEvent.cs
- DebugViewWriter.cs
- SafeThemeHandle.cs
- BamlLocalizableResourceKey.cs
- SymmetricCryptoHandle.cs
- SettingsProperty.cs
- AbstractSvcMapFileLoader.cs
- SystemWebCachingSectionGroup.cs
- BStrWrapper.cs
- NopReturnReader.cs
- LoginView.cs
- DataGridCommandEventArgs.cs
- ThicknessAnimationUsingKeyFrames.cs
- BaseTransportHeaders.cs
- DataGridPageChangedEventArgs.cs
- StructuralType.cs
- DataGridViewDataErrorEventArgs.cs