Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- InputScopeConverter.cs
- Form.cs
- _BaseOverlappedAsyncResult.cs
- MergeLocalizationDirectives.cs
- CmsUtils.cs
- ClassHandlersStore.cs
- Bits.cs
- FontFamilyIdentifier.cs
- ThicknessAnimationBase.cs
- SqlDataSourceSelectingEventArgs.cs
- MatrixUtil.cs
- Accessible.cs
- ColorTranslator.cs
- SystemBrushes.cs
- CalendarDay.cs
- Frame.cs
- CalendarDataBindingHandler.cs
- EventManager.cs
- OpenFileDialog.cs
- FirstMatchCodeGroup.cs
- CodeObjectCreateExpression.cs
- DbCommandDefinition.cs
- _CookieModule.cs
- MessageDirection.cs
- Part.cs
- MulticastNotSupportedException.cs
- CachedPathData.cs
- _PooledStream.cs
- RecordsAffectedEventArgs.cs
- Window.cs
- TableSectionStyle.cs
- ParameterBuilder.cs
- SchemaHelper.cs
- XPathPatternBuilder.cs
- Variant.cs
- WMICapabilities.cs
- SafeFileMapViewHandle.cs
- RadioButtonPopupAdapter.cs
- DescriptionCreator.cs
- WindowsFont.cs
- EnumDataContract.cs
- Type.cs
- ResourceDictionary.cs
- SerialPort.cs
- RangeBase.cs
- CodeDirectoryCompiler.cs
- HttpResponseWrapper.cs
- FormatVersion.cs
- HostedTransportConfigurationManager.cs
- ParenthesizePropertyNameAttribute.cs
- ArgumentOutOfRangeException.cs
- MenuItemAutomationPeer.cs
- DBNull.cs
- HelpEvent.cs
- AssemblyAssociatedContentFileAttribute.cs
- PeerNodeAddress.cs
- CheckoutException.cs
- SystemException.cs
- ScriptHandlerFactory.cs
- MailMessageEventArgs.cs
- LassoSelectionBehavior.cs
- UnsafeCollabNativeMethods.cs
- ConfigurationLocationCollection.cs
- mansign.cs
- ColorTransform.cs
- listitem.cs
- PolyQuadraticBezierSegment.cs
- ReadOnlyDictionary.cs
- IdentityModelStringsVersion1.cs
- BufferedWebEventProvider.cs
- RequiredAttributeAttribute.cs
- LineServices.cs
- SearchExpression.cs
- BaseCollection.cs
- Tuple.cs
- StandardOleMarshalObject.cs
- DrawItemEvent.cs
- CalendarDesigner.cs
- InteropAutomationProvider.cs
- DataGridViewLinkColumn.cs
- SemaphoreFullException.cs
- PackagePartCollection.cs
- sqlcontext.cs
- Baml2006ReaderSettings.cs
- HMACMD5.cs
- CodeGen.cs
- DictionaryKeyPropertyAttribute.cs
- PropertyDescriptors.cs
- OdbcParameterCollection.cs
- ImageAutomationPeer.cs
- ConversionContext.cs
- SchemaRegistration.cs
- Themes.cs
- ProviderConnectionPointCollection.cs
- ComplusTypeValidator.cs
- PeerName.cs
- Compilation.cs
- SignedXml.cs
- EnumConverter.cs
- ConsumerConnectionPoint.cs