Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Emitter.cs
- HelloMessage11.cs
- ArraySortHelper.cs
- BuildProvider.cs
- MatrixCamera.cs
- ZoneButton.cs
- AssemblyCache.cs
- DataGridViewEditingControlShowingEventArgs.cs
- IODescriptionAttribute.cs
- TextBox.cs
- TreeViewCancelEvent.cs
- CompilerResults.cs
- XhtmlBasicFormAdapter.cs
- _ContextAwareResult.cs
- listitem.cs
- UriTemplateClientFormatter.cs
- ReferenceTypeElement.cs
- SimpleRecyclingCache.cs
- LabelEditEvent.cs
- MailBnfHelper.cs
- XslCompiledTransform.cs
- CacheVirtualItemsEvent.cs
- PlanCompiler.cs
- GeneratedContractType.cs
- WebResourceUtil.cs
- TextInfo.cs
- SmtpNegotiateAuthenticationModule.cs
- CqlLexerHelpers.cs
- ExtensibleClassFactory.cs
- MobileFormsAuthentication.cs
- BinaryParser.cs
- SqlProcedureAttribute.cs
- HttpListenerResponse.cs
- ThemeDictionaryExtension.cs
- AlternationConverter.cs
- TableItemPattern.cs
- StagingAreaInputItem.cs
- ClientConfigurationHost.cs
- DataKeyCollection.cs
- SkinBuilder.cs
- ArraySet.cs
- SendAgentStatusRequest.cs
- QueryContext.cs
- SerializationException.cs
- ConstructorBuilder.cs
- DataGridViewTextBoxEditingControl.cs
- StoreItemCollection.cs
- SubMenuStyle.cs
- GeneralTransform3D.cs
- InputScopeNameConverter.cs
- DbDeleteCommandTree.cs
- CompiledIdentityConstraint.cs
- ToolStripSettings.cs
- SafeViewOfFileHandle.cs
- JsonByteArrayDataContract.cs
- NameScope.cs
- DiagnosticsConfigurationHandler.cs
- UInt16.cs
- SlotInfo.cs
- SyndicationSerializer.cs
- TemplateContainer.cs
- SHA512Managed.cs
- WindowsComboBox.cs
- UserControlAutomationPeer.cs
- EmissiveMaterial.cs
- OverlappedAsyncResult.cs
- DbResourceAllocator.cs
- XsltException.cs
- StylusPoint.cs
- XmlSchemaSimpleContent.cs
- PeerApplicationLaunchInfo.cs
- ChannelCredentials.cs
- WindowsProgressbar.cs
- DataBindEngine.cs
- AssemblyResourceLoader.cs
- SplitterPanel.cs
- StackOverflowException.cs
- CollectionAdapters.cs
- ScriptControl.cs
- xmlsaver.cs
- StaticResourceExtension.cs
- PerformanceCounter.cs
- FormsIdentity.cs
- SQLDecimal.cs
- XmlComment.cs
- login.cs
- WhitespaceReader.cs
- X509CertificateRecipientClientCredential.cs
- TemplateBindingExtension.cs
- PerSessionInstanceContextProvider.cs
- DataTableNewRowEvent.cs
- DataGridSortCommandEventArgs.cs
- XmlRawWriterWrapper.cs
- _NetRes.cs
- MetadataArtifactLoaderCompositeResource.cs
- SQLBinaryStorage.cs
- DataSourceCacheDurationConverter.cs
- PlaceHolder.cs
- SectionVisual.cs
- PackagePart.cs