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
- cookieexception.cs
- ListViewGroup.cs
- basevalidator.cs
- ReadOnlyDictionary.cs
- DependencyPropertyAttribute.cs
- DataGridViewCheckBoxColumn.cs
- PolyBezierSegment.cs
- DesignTimeTemplateParser.cs
- BindingWorker.cs
- XpsFilter.cs
- ParseHttpDate.cs
- SqlNodeTypeOperators.cs
- DocumentApplicationJournalEntry.cs
- ApplicationSettingsBase.cs
- WindowsFormsSectionHandler.cs
- StateBag.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- TranslateTransform.cs
- TreeSet.cs
- MenuItem.cs
- VectorKeyFrameCollection.cs
- figurelengthconverter.cs
- WebBrowserNavigatedEventHandler.cs
- VirtualPath.cs
- WebPartEditorOkVerb.cs
- CodeAssignStatement.cs
- IIS7UserPrincipal.cs
- UserControl.cs
- ImageListUtils.cs
- ListViewItemEventArgs.cs
- CollectionChangeEventArgs.cs
- TabControl.cs
- TemplateBindingExpression.cs
- MsdtcClusterUtils.cs
- HostingEnvironmentException.cs
- TablePattern.cs
- MemoryMappedViewStream.cs
- XmlSerializerFactory.cs
- ClassGenerator.cs
- DisableDpiAwarenessAttribute.cs
- DetailsViewModeEventArgs.cs
- ContainerSelectorActiveEvent.cs
- EntityObject.cs
- NullRuntimeConfig.cs
- XmlUtil.cs
- RuntimeIdentifierPropertyAttribute.cs
- FileUtil.cs
- XmlSchemaValidator.cs
- Drawing.cs
- BlockUIContainer.cs
- DataBoundControlParameterTarget.cs
- ContainerActivationHelper.cs
- UpdateCompiler.cs
- XmlUnspecifiedAttribute.cs
- Overlapped.cs
- WorkflowItemsPresenter.cs
- XhtmlBasicTextBoxAdapter.cs
- MessageBuffer.cs
- PngBitmapDecoder.cs
- CFStream.cs
- FontFamilyIdentifier.cs
- XmlSerializerNamespaces.cs
- SynchronizedCollection.cs
- TextModifierScope.cs
- CancellableEnumerable.cs
- Invariant.cs
- HierarchicalDataSourceControl.cs
- ViewStateModeByIdAttribute.cs
- PageAsyncTask.cs
- FrugalList.cs
- Point3DConverter.cs
- ALinqExpressionVisitor.cs
- SortAction.cs
- File.cs
- Model3D.cs
- LocatorPart.cs
- GroupLabel.cs
- HTMLTextWriter.cs
- ObjectDataSourceFilteringEventArgs.cs
- DataBindingHandlerAttribute.cs
- CodeDomConfigurationHandler.cs
- ListMarkerSourceInfo.cs
- AnnouncementService.cs
- AutomationPatternInfo.cs
- AspNetSynchronizationContext.cs
- ThumbAutomationPeer.cs
- TypeExtension.cs
- TypedElement.cs
- AffineTransform3D.cs
- HybridWebProxyFinder.cs
- PeerToPeerException.cs
- X509UI.cs
- Transform.cs
- MemberRelationshipService.cs
- MetadataCache.cs
- DataQuery.cs
- IntPtr.cs
- Nodes.cs
- AppModelKnownContentFactory.cs
- SqlPersonalizationProvider.cs