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
- UDPClient.cs
- TransactionOptions.cs
- Pts.cs
- HelpEvent.cs
- TypedReference.cs
- TextBoxAutoCompleteSourceConverter.cs
- PerformanceCounterCategory.cs
- RayHitTestParameters.cs
- UnmanagedMarshal.cs
- BufferedMessageWriter.cs
- SurrogateSelector.cs
- Activity.cs
- PartialTrustValidationBehavior.cs
- BamlMapTable.cs
- PeerResolverElement.cs
- ListenDesigner.cs
- Paragraph.cs
- TransformValueSerializer.cs
- TypeName.cs
- AdRotator.cs
- URLString.cs
- XamlSerializerUtil.cs
- ResourceManager.cs
- TabControlEvent.cs
- ActivityCodeDomSerializer.cs
- SqlCacheDependencyDatabase.cs
- Attributes.cs
- SvcMapFile.cs
- SizeAnimationBase.cs
- ContractMethodInfo.cs
- ImageSource.cs
- CodeGenerator.cs
- XslVisitor.cs
- FilteredAttributeCollection.cs
- SqlTypesSchemaImporter.cs
- Model3DGroup.cs
- GC.cs
- oledbconnectionstring.cs
- TypeTypeConverter.cs
- XmlChildEnumerator.cs
- OleDbInfoMessageEvent.cs
- NativeMethodsCLR.cs
- BamlRecords.cs
- EDesignUtil.cs
- BulletedListEventArgs.cs
- EarlyBoundInfo.cs
- FixedSOMLineCollection.cs
- CompModSwitches.cs
- PopupRoot.cs
- WindowsClientElement.cs
- OptimisticConcurrencyException.cs
- Query.cs
- SiteMapHierarchicalDataSourceView.cs
- DataControlPagerLinkButton.cs
- TextElement.cs
- PropertyEntry.cs
- Point3DConverter.cs
- DecoderBestFitFallback.cs
- XpsFilter.cs
- MDIWindowDialog.cs
- IRCollection.cs
- ParallelForEach.cs
- IISUnsafeMethods.cs
- XmlUrlResolver.cs
- FormatConvertedBitmap.cs
- ButtonChrome.cs
- SemanticBasicElement.cs
- SQLByteStorage.cs
- DataTableNameHandler.cs
- MatrixTransform3D.cs
- ColorContext.cs
- DiscoveryServiceExtension.cs
- NamespaceEmitter.cs
- SmtpDigestAuthenticationModule.cs
- RouteValueDictionary.cs
- ECDiffieHellmanCngPublicKey.cs
- LinkLabelLinkClickedEvent.cs
- CellIdBoolean.cs
- DynamicDataRoute.cs
- ProxyWebPartManager.cs
- ScriptReference.cs
- DotExpr.cs
- SplashScreen.cs
- RelationshipDetailsRow.cs
- IBuiltInEvidence.cs
- Polygon.cs
- ListViewDesigner.cs
- Util.cs
- IpcChannelHelper.cs
- OperationCanceledException.cs
- RecognizedPhrase.cs
- StateManagedCollection.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- WhileDesigner.xaml.cs
- SqlDataRecord.cs
- PolygonHotSpot.cs
- BaseCodePageEncoding.cs
- CrossAppDomainChannel.cs
- DesignerView.xaml.cs
- EntitySqlQueryBuilder.cs