Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2003

Tip: Looking for answers? Try searching our database.

StringBuilder and PCHAR[]

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Schley Andrew Kutz - 21 Oct 2003 13:14 GMT
I am iterating through 454 rows of a table and with each row I use the ID
field to form a URI for a contact in a public folder on my exchange server.

My memory keeps growing though.  I think it is because I reconstruct my URI
each time.  I have done this 2 ways and I want to know something.  How is
this ...

StringBuilder sb = new StringBuilder( 255, 255 );
for ( int x = 0; x < rs.Rows.Count; ++x )
{
   if ( sb.Length > 0 ) sb.Remove( 0, sb.Length );
   sb.AppendFormat( "{0}/{1}.EML", URI_PREFIX, rs.Rows[ x ][ "ID" ] );
   ...
}

any more efficient than this

for ( int x = 0; x < rs.Rows.Count; ++x )
   string uri = string.Format( "{0}/{1}.EML", URI_PREFIX, rs.Rows[ x ][
"ID" ] );

The first snippet should be far more effective since I am pre-allocating my
buffer.  However, since the ADODB.Connection object takes a string as its
connection source and string are immutable in dot net, whenever I call the
ToString method of the StringBuilder to give to the connection object, it is
going to allocate new memory for that string, correct?

I have found no way in C# to make sequential string operations occupy the
same memory.  This is just plain wasteful.

Where in the hell then is the efficiency in this?  Why is this better than C
or C++ where you can pass a pointer to an array of char so that you do not
re-create a string in memory from a buffer you pre-allocated for this very
reason to give to a function?

-a
Girish Bharadwaj - 21 Oct 2003 13:39 GMT
> I am iterating through 454 rows of a table and with each row I use the ID
> field to form a URI for a contact in a public folder on my exchange server.
[quoted text clipped - 32 lines]
>
> -a

In the particular case you have provided, I dont think the two loops are
similar in efficiency. In fact, I think the first one might be a bit
slower since it needs to do a Remove() before appending. If you are
getting this from the table, you might want to consider doing right in
the database, if the URI_PREFIX is a constant, you can probably write a
SQL function or s select statement which appends both and returns the
resulting row..
Of course, I am not sure it performs much better..

Signature

Girish Bharadwaj


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.