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
- HotCommands.cs
- PerformanceCounterLib.cs
- ZipIOLocalFileDataDescriptor.cs
- PathSegment.cs
- QuaternionAnimationUsingKeyFrames.cs
- _SafeNetHandles.cs
- MenuCommandsChangedEventArgs.cs
- AnnotationMap.cs
- EndSelectCardRequest.cs
- XhtmlTextWriter.cs
- PenThreadWorker.cs
- InteropBitmapSource.cs
- SQLMoney.cs
- GridProviderWrapper.cs
- TreeViewHitTestInfo.cs
- MoveSizeWinEventHandler.cs
- Debugger.cs
- PerformanceCounterPermissionEntryCollection.cs
- WCFBuildProvider.cs
- TypeContext.cs
- TablePatternIdentifiers.cs
- EventListener.cs
- SizeValueSerializer.cs
- ImageBrush.cs
- XomlCompilerHelpers.cs
- Group.cs
- Pair.cs
- WebColorConverter.cs
- ObjectDisposedException.cs
- Site.cs
- EvidenceTypeDescriptor.cs
- UiaCoreApi.cs
- ScriptingProfileServiceSection.cs
- Int64Storage.cs
- TypedDataSourceCodeGenerator.cs
- UITypeEditor.cs
- httpapplicationstate.cs
- EntityCollection.cs
- HtmlButton.cs
- DrawingAttributes.cs
- DocumentApplicationJournalEntryEventArgs.cs
- SamlConstants.cs
- querybuilder.cs
- ButtonBase.cs
- RequestCacheEntry.cs
- RoutedPropertyChangedEventArgs.cs
- DataControlField.cs
- ObjectKeyFrameCollection.cs
- DoubleStorage.cs
- XmlSchemaAttributeGroup.cs
- WindowsGraphics2.cs
- TypedTableBaseExtensions.cs
- XmlSchemaAttribute.cs
- MetabaseServerConfig.cs
- WebPartAuthorizationEventArgs.cs
- Quad.cs
- ImageAttributes.cs
- HostingPreferredMapPath.cs
- ToolBarButtonClickEvent.cs
- ObjectHandle.cs
- ZipIOModeEnforcingStream.cs
- DesignTimeDataBinding.cs
- Base64Stream.cs
- SafeSecurityHandles.cs
- ThaiBuddhistCalendar.cs
- EffectiveValueEntry.cs
- TextDecoration.cs
- ExtractedStateEntry.cs
- ISessionStateStore.cs
- XamlNamespaceHelper.cs
- HostUtils.cs
- DynamicVirtualDiscoSearcher.cs
- BaseDataListActionList.cs
- DecoratedNameAttribute.cs
- TiffBitmapEncoder.cs
- CompositionDesigner.cs
- ContentType.cs
- WebBrowserSiteBase.cs
- XPathPatternParser.cs
- COM2Enum.cs
- CodeSubDirectory.cs
- WebScriptMetadataMessage.cs
- _HTTPDateParse.cs
- EndEvent.cs
- XmlSchemaResource.cs
- _ListenerResponseStream.cs
- CharConverter.cs
- ControlPropertyNameConverter.cs
- SimpleMailWebEventProvider.cs
- TraceFilter.cs
- RadioButtonList.cs
- HealthMonitoringSection.cs
- CellTreeNodeVisitors.cs
- Graphics.cs
- DeploymentSection.cs
- Timer.cs
- HtmlControlPersistable.cs
- FloaterParaClient.cs
- BitmapMetadataBlob.cs
- RijndaelManagedTransform.cs