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
- TransformCollection.cs
- NoneExcludedImageIndexConverter.cs
- DataColumnPropertyDescriptor.cs
- ListBase.cs
- XamlGridLengthSerializer.cs
- Solver.cs
- assemblycache.cs
- MultiView.cs
- IisTraceWebEventProvider.cs
- MobileUserControlDesigner.cs
- SqlMethodAttribute.cs
- CompressEmulationStream.cs
- ZoneMembershipCondition.cs
- CompatibleComparer.cs
- ProfileServiceManager.cs
- ObjectDataSourceSelectingEventArgs.cs
- X509CertificateClaimSet.cs
- FixedSOMGroup.cs
- ToolStripLabel.cs
- LightweightCodeGenerator.cs
- ErrorFormatter.cs
- HttpResponse.cs
- ProgressBar.cs
- ConfigXmlElement.cs
- Html32TextWriter.cs
- DetailsViewUpdateEventArgs.cs
- AttributeEmitter.cs
- TemplateGroupCollection.cs
- ValueConversionAttribute.cs
- SqlPersistenceWorkflowInstanceDescription.cs
- VSWCFServiceContractGenerator.cs
- List.cs
- IRCollection.cs
- InheritablePropertyChangeInfo.cs
- HostProtectionPermission.cs
- HttpResponse.cs
- WebBrowserSiteBase.cs
- GridItemCollection.cs
- CodeConditionStatement.cs
- EmptyElement.cs
- WebScriptMetadataMessageEncoderFactory.cs
- AddressHeaderCollection.cs
- GridViewEditEventArgs.cs
- Visitors.cs
- EntityConnection.cs
- OdbcInfoMessageEvent.cs
- ApplyTemplatesAction.cs
- WriteableBitmap.cs
- HtmlElementEventArgs.cs
- HttpRequest.cs
- ToolStripOverflowButton.cs
- InstanceKeyNotReadyException.cs
- CapabilitiesAssignment.cs
- sitestring.cs
- SmiGettersStream.cs
- ListenerElementsCollection.cs
- ObjectListShowCommandsEventArgs.cs
- DateTimeParse.cs
- DataControlPagerLinkButton.cs
- HtmlInputReset.cs
- DynamicMethod.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- FormsAuthenticationUser.cs
- TreeIterator.cs
- HTTPNotFoundHandler.cs
- MediaTimeline.cs
- UnSafeCharBuffer.cs
- PngBitmapDecoder.cs
- HttpApplicationStateWrapper.cs
- DataGridHelper.cs
- SettingsContext.cs
- WindowsTab.cs
- CheckBoxList.cs
- keycontainerpermission.cs
- StorageMappingItemLoader.cs
- XmlWrappingWriter.cs
- WorkflowInspectionServices.cs
- uribuilder.cs
- HostingEnvironmentWrapper.cs
- HtmlInputControl.cs
- _AcceptOverlappedAsyncResult.cs
- EntityTypeEmitter.cs
- LinearQuaternionKeyFrame.cs
- DeclaredTypeValidator.cs
- Pkcs7Signer.cs
- ResourceAssociationSet.cs
- EncoderBestFitFallback.cs
- WorkflowControlClient.cs
- Material.cs
- LineSegment.cs
- StringFunctions.cs
- Page.cs
- AutomationPeer.cs
- FaultReason.cs
- EnvelopedSignatureTransform.cs
- Accessors.cs
- DataSourceSelectArguments.cs
- RegistryKey.cs
- XPathExpr.cs
- DataGridViewAccessibleObject.cs