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
- Classification.cs
- EditableTreeList.cs
- CalendarDay.cs
- TypeSystemHelpers.cs
- XmlUrlEditor.cs
- KeyedCollection.cs
- DefaultAssemblyResolver.cs
- IisTraceListener.cs
- ConfigXmlReader.cs
- PerfCounterSection.cs
- StructuredTypeEmitter.cs
- BulletedListEventArgs.cs
- PropertyGrid.cs
- RelationshipConstraintValidator.cs
- HwndSourceKeyboardInputSite.cs
- ChannelBinding.cs
- WebBrowserNavigatedEventHandler.cs
- CodeTypeReferenceCollection.cs
- HTTPNotFoundHandler.cs
- ToolStripItemRenderEventArgs.cs
- ClickablePoint.cs
- StaticExtension.cs
- BamlRecordReader.cs
- BuildProvider.cs
- SimpleType.cs
- StreamReader.cs
- ConnectionManagementElement.cs
- DataGridViewCheckBoxCell.cs
- NavigationFailedEventArgs.cs
- EventHandlerService.cs
- PersonalizableAttribute.cs
- ButtonBaseAdapter.cs
- Monitor.cs
- SignatureHelper.cs
- ObjectDataSourceChooseMethodsPanel.cs
- SchemaElementDecl.cs
- XmlSerializerVersionAttribute.cs
- SimpleExpression.cs
- ClusterRegistryConfigurationProvider.cs
- ImplicitInputBrush.cs
- AdRotatorDesigner.cs
- SafeNativeMethods.cs
- CategoryNameCollection.cs
- FilterQuery.cs
- ProxyGenerator.cs
- RetriableClipboard.cs
- DbConnectionPool.cs
- TransactionManagerProxy.cs
- TextElementEditingBehaviorAttribute.cs
- SoapHeaders.cs
- GenericWebPart.cs
- DiffuseMaterial.cs
- SqlException.cs
- DbParameterHelper.cs
- BaseParagraph.cs
- XXXInfos.cs
- bindurihelper.cs
- ObjectPersistData.cs
- _NTAuthentication.cs
- ZoneIdentityPermission.cs
- StreamInfo.cs
- mda.cs
- PrivateFontCollection.cs
- Expressions.cs
- future.cs
- ConditionCollection.cs
- RtfFormatStack.cs
- BoundColumn.cs
- QueryRewriter.cs
- KeyboardNavigation.cs
- DataGridViewElement.cs
- WindowsToolbarItemAsMenuItem.cs
- RefreshInfo.cs
- DataServiceRequest.cs
- FileDataSourceCache.cs
- LambdaCompiler.Address.cs
- MatrixIndependentAnimationStorage.cs
- Attachment.cs
- CompilerGeneratedAttribute.cs
- ExtendedPropertyInfo.cs
- SByte.cs
- AppDomainShutdownMonitor.cs
- MappingException.cs
- TryExpression.cs
- WinInetCache.cs
- ByteBufferPool.cs
- Dump.cs
- SettingsProviderCollection.cs
- DataGridRelationshipRow.cs
- ListBoxAutomationPeer.cs
- WindowsGraphics2.cs
- DataPagerFieldItem.cs
- TextEditorSpelling.cs
- FrameworkElement.cs
- RequestQueryProcessor.cs
- ActivationServices.cs
- WorkflowWebService.cs
- MobileErrorInfo.cs
- CommandValueSerializer.cs
- HtmlElementErrorEventArgs.cs