Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- XpsS0ValidatingLoader.cs
- ServiceDescription.cs
- CodeDomConfigurationHandler.cs
- DataServiceStreamResponse.cs
- DesignRelation.cs
- ObjectSet.cs
- Size3D.cs
- ValidatedControlConverter.cs
- ClickablePoint.cs
- FacetChecker.cs
- XamlReaderHelper.cs
- HasCopySemanticsAttribute.cs
- InvokeMemberBinder.cs
- Root.cs
- DoubleConverter.cs
- BamlTreeMap.cs
- UserValidatedEventArgs.cs
- XmlObjectSerializerReadContext.cs
- Viewport3DVisual.cs
- ParserHooks.cs
- SizeAnimationBase.cs
- StreamGeometryContext.cs
- SmiRequestExecutor.cs
- WebPartZoneBase.cs
- EditingScopeUndoUnit.cs
- ListParaClient.cs
- MessagePropertyAttribute.cs
- ExtendedPropertyCollection.cs
- CollectionConverter.cs
- ListChangedEventArgs.cs
- HttpPostedFile.cs
- BaseDataList.cs
- MultipleCopiesCollection.cs
- wgx_render.cs
- DrawToolTipEventArgs.cs
- TextFormattingConverter.cs
- ThumbAutomationPeer.cs
- DataGridTable.cs
- InternalControlCollection.cs
- newinstructionaction.cs
- BreadCrumbTextConverter.cs
- TrackingDataItemValue.cs
- TreeNode.cs
- SchemaSetCompiler.cs
- CustomGrammar.cs
- MediaElementAutomationPeer.cs
- DeclarativeCatalogPart.cs
- XmlDataFileEditor.cs
- CodeRegionDirective.cs
- FilterException.cs
- HitTestParameters.cs
- ControllableStoryboardAction.cs
- PageBuildProvider.cs
- VisualBrush.cs
- FixedPage.cs
- ComIntegrationManifestGenerator.cs
- Synchronization.cs
- DataGrid.cs
- SynchronizationLockException.cs
- Helpers.cs
- RuntimeArgumentHandle.cs
- FixedTextPointer.cs
- CompiledRegexRunner.cs
- CheckBoxFlatAdapter.cs
- StyleSheetComponentEditor.cs
- EntityCommandCompilationException.cs
- MessageBodyDescription.cs
- RouteCollection.cs
- SchemaElementDecl.cs
- XamlLoadErrorInfo.cs
- AuthorizationRule.cs
- LinqDataSourceInsertEventArgs.cs
- DebugController.cs
- PackagingUtilities.cs
- FactoryGenerator.cs
- TraceLog.cs
- TimelineClockCollection.cs
- CompatibleIComparer.cs
- CachingHintValidation.cs
- MemberHolder.cs
- DispatcherHookEventArgs.cs
- EventBuilder.cs
- DecoderNLS.cs
- FixedTextBuilder.cs
- GorillaCodec.cs
- InfoCardBaseException.cs
- SafeArrayTypeMismatchException.cs
- AvTraceDetails.cs
- CodeTypeReference.cs
- CalendarAutoFormat.cs
- WebOperationContext.cs
- XmlNamespaceMappingCollection.cs
- ElementsClipboardData.cs
- FileCodeGroup.cs
- EmptyQuery.cs
- SafeNativeMethodsMilCoreApi.cs
- EventSinkHelperWriter.cs
- HtmlImage.cs
- FileSystemInfo.cs
- BmpBitmapDecoder.cs