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
- SqlExpressionNullability.cs
- XmlSchemaComplexContentRestriction.cs
- Int16Converter.cs
- IMembershipProvider.cs
- PropertyGroupDescription.cs
- SafeNativeMethods.cs
- ApplicationServiceManager.cs
- ResponseBodyWriter.cs
- NamespaceListProperty.cs
- InvalidDataException.cs
- DecimalConverter.cs
- NaturalLanguageHyphenator.cs
- ProfessionalColors.cs
- SqlUtil.cs
- InternalConfigRoot.cs
- JsonReaderDelegator.cs
- HtmlTableCell.cs
- ModuleBuilder.cs
- HMAC.cs
- XsdBuilder.cs
- EntityObject.cs
- _emptywebproxy.cs
- DrawingImage.cs
- CompositeFontFamily.cs
- VisualBrush.cs
- JumpTask.cs
- EnterpriseServicesHelper.cs
- TextLineBreak.cs
- control.ime.cs
- Attribute.cs
- SimpleFieldTemplateUserControl.cs
- SqlUnionizer.cs
- MenuCommandService.cs
- PrintControllerWithStatusDialog.cs
- FunctionDetailsReader.cs
- HttpStreamXmlDictionaryWriter.cs
- XmlNavigatorStack.cs
- ResXResourceSet.cs
- CodeDefaultValueExpression.cs
- StrokeNodeData.cs
- SmtpNtlmAuthenticationModule.cs
- CodeBlockBuilder.cs
- DbReferenceCollection.cs
- TypefaceMap.cs
- TabItem.cs
- MobileUserControl.cs
- NavigationProperty.cs
- DataContractSerializer.cs
- ParseChildrenAsPropertiesAttribute.cs
- MailHeaderInfo.cs
- TextTreeExtractElementUndoUnit.cs
- StateManagedCollection.cs
- Renderer.cs
- NativeCppClassAttribute.cs
- PersonalizationState.cs
- ExtensionFile.cs
- ParseElement.cs
- ExceptionUtil.cs
- ServiceContractViewControl.Designer.cs
- PenContexts.cs
- XdrBuilder.cs
- CompilerHelpers.cs
- SystemIPv6InterfaceProperties.cs
- Vector3DAnimationBase.cs
- TimeSpanValidator.cs
- AnimationLayer.cs
- CompilerLocalReference.cs
- HttpFileCollectionWrapper.cs
- HttpCapabilitiesSectionHandler.cs
- ConnectionStringSettings.cs
- ConfigurationHelpers.cs
- ColumnPropertiesGroup.cs
- WindowsSlider.cs
- LinqDataSourceDisposeEventArgs.cs
- TextComposition.cs
- ValidationEventArgs.cs
- ThreadAbortException.cs
- WebPartDisplayModeEventArgs.cs
- CryptoProvider.cs
- _LocalDataStoreMgr.cs
- PagedDataSource.cs
- WebColorConverter.cs
- CommandPlan.cs
- InfoCardUIAgent.cs
- ColumnMapCopier.cs
- MULTI_QI.cs
- Column.cs
- EdmFunctions.cs
- TextEndOfLine.cs
- ComplexPropertyEntry.cs
- ParseElement.cs
- CommandSet.cs
- RSAPKCS1SignatureDeformatter.cs
- Util.cs
- RecordsAffectedEventArgs.cs
- XslAstAnalyzer.cs
- UnknownBitmapDecoder.cs
- ClientBuildManagerCallback.cs
- XmlSortKey.cs
- ComPersistableTypeElement.cs