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
- PropertyChangingEventArgs.cs
- PrivilegeNotHeldException.cs
- SoapIncludeAttribute.cs
- SecurityUtils.cs
- VirtualPathUtility.cs
- GeometryGroup.cs
- IssuanceTokenProviderState.cs
- ListViewItem.cs
- IRCollection.cs
- ObjectTag.cs
- AdvancedBindingEditor.cs
- RequestDescription.cs
- SmiRequestExecutor.cs
- UpdateTracker.cs
- SharedPersonalizationStateInfo.cs
- ContainerParagraph.cs
- NavigationProgressEventArgs.cs
- WebPartCatalogAddVerb.cs
- Command.cs
- ComAdminInterfaces.cs
- CachedFontFamily.cs
- ConfigurationSectionCollection.cs
- X509ChainElement.cs
- MemoryResponseElement.cs
- StandardToolWindows.cs
- HashCoreRequest.cs
- Buffer.cs
- EventBookmark.cs
- DbDataAdapter.cs
- LicenseManager.cs
- WebPartRestoreVerb.cs
- DownloadProgressEventArgs.cs
- DefaultParameterValueAttribute.cs
- UdpDiscoveryEndpoint.cs
- ArglessEventHandlerProxy.cs
- ApplicationTrust.cs
- XmlSchemaAnnotated.cs
- MeshGeometry3D.cs
- PageParserFilter.cs
- ListBoxAutomationPeer.cs
- COM2ComponentEditor.cs
- MutexSecurity.cs
- AuthenticationModulesSection.cs
- RouteItem.cs
- PaintValueEventArgs.cs
- DataGridRow.cs
- DataGridViewControlCollection.cs
- GradientSpreadMethodValidation.cs
- RtfToXamlLexer.cs
- Currency.cs
- ProfileModule.cs
- TextMetrics.cs
- ClientApiGenerator.cs
- MsmqReceiveHelper.cs
- DirectoryNotFoundException.cs
- ColumnHeaderConverter.cs
- EncoderNLS.cs
- Rect3DConverter.cs
- WebPartDisplayModeEventArgs.cs
- DataGridSortCommandEventArgs.cs
- CommonObjectSecurity.cs
- CodeNamespace.cs
- TextTreeText.cs
- DynamicPhysicalDiscoSearcher.cs
- WindowsTreeView.cs
- CqlGenerator.cs
- _ListenerAsyncResult.cs
- GridViewDeleteEventArgs.cs
- SubqueryRules.cs
- SpeechSynthesizer.cs
- AudioLevelUpdatedEventArgs.cs
- PropertyDescriptorCollection.cs
- SqlDataSourceConnectionPanel.cs
- TabRenderer.cs
- FormsIdentity.cs
- ColumnBinding.cs
- ZipIOCentralDirectoryFileHeader.cs
- PerfCounters.cs
- FreezableOperations.cs
- BaseHashHelper.cs
- ColumnMap.cs
- XPathDocumentNavigator.cs
- NotifyInputEventArgs.cs
- VirtualPathData.cs
- BulletedListEventArgs.cs
- CompositeFontParser.cs
- InvalidMessageContractException.cs
- TextDataBindingHandler.cs
- CharEntityEncoderFallback.cs
- CompiledQueryCacheKey.cs
- Point3DCollectionConverter.cs
- ByteBufferPool.cs
- ResourceType.cs
- ToolZone.cs
- DataPagerField.cs
- ValidationErrorCollection.cs
- XmlILIndex.cs
- MediaElement.cs
- WSHttpBindingCollectionElement.cs
- QualificationDataItem.cs