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
- PenContext.cs
- ProviderSettingsCollection.cs
- TemplateManager.cs
- Int64KeyFrameCollection.cs
- OrderPreservingSpoolingTask.cs
- SchemaObjectWriter.cs
- Vector3DValueSerializer.cs
- SafeNativeMethods.cs
- GeneralTransform3D.cs
- PropertyGridCommands.cs
- CodeTypeDelegate.cs
- IndicFontClient.cs
- OleDbException.cs
- XamlVector3DCollectionSerializer.cs
- GraphicsPath.cs
- BaseParser.cs
- ArithmeticException.cs
- TraceHwndHost.cs
- ReadWriteSpinLock.cs
- SqlFlattener.cs
- DataGridViewCellEventArgs.cs
- IssuedTokenServiceCredential.cs
- TdsParameterSetter.cs
- ISFTagAndGuidCache.cs
- SafeNativeMethods.cs
- EventlogProvider.cs
- IgnorePropertiesAttribute.cs
- HttpPostedFileWrapper.cs
- HuffCodec.cs
- ReachVisualSerializer.cs
- CapabilitiesState.cs
- ButtonBaseAutomationPeer.cs
- Converter.cs
- _IPv4Address.cs
- TypeReference.cs
- XmlImplementation.cs
- SpecularMaterial.cs
- ProgressChangedEventArgs.cs
- DataGridViewCellStateChangedEventArgs.cs
- ExpressionContext.cs
- SiteIdentityPermission.cs
- AsymmetricKeyExchangeFormatter.cs
- _CacheStreams.cs
- HttpResponseWrapper.cs
- OdbcStatementHandle.cs
- HttpListenerException.cs
- DataTableMappingCollection.cs
- ConfigurationSectionGroup.cs
- SystemWebExtensionsSectionGroup.cs
- TimeSpanConverter.cs
- RequiredFieldValidator.cs
- WebPartDisplayModeCollection.cs
- AsymmetricKeyExchangeFormatter.cs
- DefaultTextStoreTextComposition.cs
- MobileRedirect.cs
- ViewSimplifier.cs
- CallId.cs
- AlternateView.cs
- AccessorTable.cs
- ComplexObject.cs
- ListBindingHelper.cs
- CollectionChange.cs
- RootBrowserWindowAutomationPeer.cs
- XPathParser.cs
- NativeMethods.cs
- ResourceContainer.cs
- ParseElement.cs
- ConnectionManagementSection.cs
- ObjectViewQueryResultData.cs
- UIPermission.cs
- StringUtil.cs
- AutomationEvent.cs
- _RegBlobWebProxyDataBuilder.cs
- PackagingUtilities.cs
- SettingsSection.cs
- OciLobLocator.cs
- AttributeAction.cs
- CodeCatchClause.cs
- IQueryable.cs
- CodePropertyReferenceExpression.cs
- HtmlButton.cs
- HebrewCalendar.cs
- ComponentConverter.cs
- TextServicesProperty.cs
- ValueTypePropertyReference.cs
- Parameter.cs
- ConditionCollection.cs
- PropertyTabChangedEvent.cs
- RepeatButton.cs
- JsonObjectDataContract.cs
- FloatUtil.cs
- FrameworkName.cs
- ArgumentDesigner.xaml.cs
- SharedUtils.cs
- XmlSchemaSimpleTypeList.cs
- HttpResponseHeader.cs
- GregorianCalendar.cs
- ToolStripPanelRenderEventArgs.cs
- ConfigUtil.cs
- PrintPreviewControl.cs