Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- Options.cs
- ParentQuery.cs
- VirtualizingStackPanel.cs
- Vector.cs
- ExitEventArgs.cs
- SoapSchemaImporter.cs
- Util.cs
- Control.cs
- HitTestParameters.cs
- SqlMethodAttribute.cs
- QueryRewriter.cs
- PrintingPermission.cs
- ScriptManagerProxy.cs
- ExternalDataExchangeService.cs
- MouseActionConverter.cs
- RoleManagerEventArgs.cs
- SrgsRule.cs
- HiddenField.cs
- DataRowChangeEvent.cs
- ApplicationActivator.cs
- NetworkCredential.cs
- WebPartEditVerb.cs
- StylusButtonCollection.cs
- TreeViewEvent.cs
- MarkedHighlightComponent.cs
- TraceListeners.cs
- SendActivity.cs
- CodeExpressionStatement.cs
- SqlWriter.cs
- DataListItemCollection.cs
- ToolStripDropDownMenu.cs
- RemotingConfiguration.cs
- WebDisplayNameAttribute.cs
- MimeMapping.cs
- LingerOption.cs
- PluralizationServiceUtil.cs
- RSAProtectedConfigurationProvider.cs
- X509Certificate.cs
- DocumentViewer.cs
- TraceHandler.cs
- Underline.cs
- OleDbPermission.cs
- CompositeFontInfo.cs
- DbUpdateCommandTree.cs
- EnumValidator.cs
- RenderOptions.cs
- TiffBitmapEncoder.cs
- Operators.cs
- OleAutBinder.cs
- Pair.cs
- _Connection.cs
- SqlDelegatedTransaction.cs
- SchemaCollectionCompiler.cs
- ellipse.cs
- Compiler.cs
- filewebrequest.cs
- NameValueCache.cs
- PathTooLongException.cs
- MaskedTextBox.cs
- MaskDesignerDialog.cs
- ConnectionManagementElementCollection.cs
- ContextMarshalException.cs
- TabControlDesigner.cs
- PingReply.cs
- AuthenticationService.cs
- DSASignatureFormatter.cs
- CodeVariableReferenceExpression.cs
- SQLBytesStorage.cs
- SapiRecognizer.cs
- CharacterBuffer.cs
- SegmentInfo.cs
- ISFTagAndGuidCache.cs
- TabletDevice.cs
- EditorReuseAttribute.cs
- LogRecordSequence.cs
- FaultContext.cs
- HttpRequestCacheValidator.cs
- AppLevelCompilationSectionCache.cs
- ThreadNeutralSemaphore.cs
- Pts.cs
- StrokeCollection2.cs
- ActivationServices.cs
- CachedRequestParams.cs
- storagemappingitemcollection.viewdictionary.cs
- SafeNativeMemoryHandle.cs
- NativeMethods.cs
- NameValueCollection.cs
- CodePrimitiveExpression.cs
- SafeRegistryHandle.cs
- ExeContext.cs
- Size.cs
- DurationConverter.cs
- CompileXomlTask.cs
- HtmlEncodedRawTextWriter.cs
- Documentation.cs
- MenuEventArgs.cs
- CounterSampleCalculator.cs
- Rectangle.cs
- XmlBinaryReader.cs
- EntitySetBase.cs