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
- FontDialog.cs
- ResourceCollectionInfo.cs
- InvokePatternIdentifiers.cs
- DoubleStorage.cs
- SendMailErrorEventArgs.cs
- ACE.cs
- UnauthorizedAccessException.cs
- SafeNativeMethods.cs
- AutoGeneratedFieldProperties.cs
- RegexWorker.cs
- XpsColorContext.cs
- PenContexts.cs
- ToolStripOverflowButton.cs
- MsmqActivation.cs
- IChannel.cs
- SqlUnionizer.cs
- TrustLevel.cs
- EntityDataSourceMemberPath.cs
- PrinterSettings.cs
- WorkflowQueueInfo.cs
- ClassHandlersStore.cs
- RectIndependentAnimationStorage.cs
- TranslateTransform.cs
- ActivityCodeDomSerializationManager.cs
- Vector3D.cs
- SamlDelegatingWriter.cs
- WinEventHandler.cs
- UserNameSecurityTokenProvider.cs
- _HTTPDateParse.cs
- ResourceProviderFactory.cs
- DispatchWrapper.cs
- DbFunctionCommandTree.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- RemotingConfigParser.cs
- PeerChannelListener.cs
- SqlCommand.cs
- ExpressionBuilder.cs
- pingexception.cs
- MetadataArtifactLoaderResource.cs
- MarshalByValueComponent.cs
- WebServiceErrorEvent.cs
- ViewBox.cs
- ValidatingPropertiesEventArgs.cs
- DurableMessageDispatchInspector.cs
- Selection.cs
- PolyBezierSegmentFigureLogic.cs
- XmlSchemaFacet.cs
- NativeMethods.cs
- ConnectionsZone.cs
- PkcsUtils.cs
- Base64Encoder.cs
- XmlUtil.cs
- WpfPayload.cs
- PolicyValidationException.cs
- ConfigurationStrings.cs
- DefaultPropertyAttribute.cs
- SqlDataSourceView.cs
- PageSettings.cs
- FontWeight.cs
- DataRowCollection.cs
- CornerRadius.cs
- Int16Animation.cs
- _ListenerRequestStream.cs
- ListViewDataItem.cs
- WebPartConnectionsCancelVerb.cs
- CompleteWizardStep.cs
- MultipleViewPatternIdentifiers.cs
- FrameAutomationPeer.cs
- AllowedAudienceUriElementCollection.cs
- XslCompiledTransform.cs
- Drawing.cs
- URLIdentityPermission.cs
- EnumType.cs
- LinkArea.cs
- TCPListener.cs
- SqlExpressionNullability.cs
- ReplyAdapterChannelListener.cs
- ToolStripLocationCancelEventArgs.cs
- CurrentChangingEventManager.cs
- AttachInfo.cs
- BuiltInPermissionSets.cs
- documentsequencetextview.cs
- DbMetaDataColumnNames.cs
- HttpCapabilitiesBase.cs
- NetworkInformationException.cs
- IriParsingElement.cs
- UInt64Converter.cs
- XmlDataProvider.cs
- XmlDocumentType.cs
- CapabilitiesState.cs
- XPathException.cs
- Ray3DHitTestResult.cs
- TypeUnloadedException.cs
- WorkflowDebuggerSteppingAttribute.cs
- VBCodeProvider.cs
- NamespaceCollection.cs
- IisTraceListener.cs
- ConsumerConnectionPointCollection.cs
- Label.cs
- WebExceptionStatus.cs