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 4 3464 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 can't find something to back it up at the moment, but I'm pretty
sure I've read that the runtime can optimize this by "detatching" the
memory used by the StringBuilder and turning it into a String, without
allocating new memory.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Mattias,
I think I know to what you refer. The StringBuilder does detach the buffer
to static memory when you call ToString the first time and each subsequent
call uses that formed string, but the documentation says if you "alter the
buffer" the next time you call ToString a new string will get created in
memory.
What it is unclear on is if that means the contents of the buffer, or the
size of the buffer.
Ideas?
-a
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... whenever I call the ToString method of the StringBuilder to give to the connection object, it
isgoing to allocate new memory for that string, correct?
I can't find something to back it up at the moment, but I'm pretty sure I've read that the runtime can optimize this by "detatching" the memory used by the StringBuilder and turning it into a String, without allocating new memory. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ Please reply only to the newsgroup.
In the words of Pink Floyd, "Is there anyone out there?"
-a
"Schley Andrew Kutz" <ak***@austin.utexas.edu> wrote in message news:<1D*******************@twister.austin.rr.com> ... Mattias,
I think I know to what you refer. The StringBuilder does detach the buffer to static memory when you call ToString the first time and each subsequent call uses that formed string, but the documentation says if you "alter the buffer" the next time you call ToString a new string will get created in memory.
What it is unclear on is if that means the contents of the buffer, or the size of the buffer.
Ideas?
-a
"Mattias Sjögren" <ma********************@mvps.org> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...whenever I call the ToString method of the StringBuilder to give to the connection object, it isgoing to allocate new memory for that string, correct?
I can't find something to back it up at the moment, but I'm pretty sure I've read that the runtime can optimize this by "detatching" the memory used by the StringBuilder and turning it into a String, without allocating new memory. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ Please reply only to the newsgroup.
In the words of Pink Floyd, "Is there anyone out there?"
-a
"Schley Andrew Kutz" <ak***@austin.utexas.edu> wrote in message news:<1D*******************@twister.austin.rr.com> ... Mattias,
I think I know to what you refer. The StringBuilder does detach the buffer to static memory when you call ToString the first time and each subsequent call uses that formed string, but the documentation says if you "alter the buffer" the next time you call ToString a new string will get created in memory.
What it is unclear on is if that means the contents of the buffer, or the size of the buffer.
Ideas?
-a
"Mattias Sjögren" <ma********************@mvps.org> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...whenever I call the ToString method of the StringBuilder to give to the connection object, it isgoing to allocate new memory for that string, correct?
I can't find something to back it up at the moment, but I'm pretty sure I've read that the runtime can optimize this by "detatching" the memory used by the StringBuilder and turning it into a String, without allocating new memory. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ Please reply only to the newsgroup.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kevin C |
last post by:
Quick Question:
StringBuilder is obviously more efficient dealing with string concatenations
than the old '+=' method... however, in dealing with relatively large string
concatenations (ie,...
|
by: Alvin Bruney |
last post by:
On the advice of a user, I've timed stringbuilder v string. Here are the
results.
Here are the numbers:
Total # queries 3747
Time in Milliseconds
StringBuilder: String...
|
by: Craig Kenisston |
last post by:
Hi,
I have a dll that must return a string to a C# .Net application and also
needs to server a Delphi application.
I have defined my delphi function like this :
function GetString(var strPtr...
|
by: Mo |
last post by:
I am having problem with marshaling struct in C#.
//the original C++ struct
typedef struct _tagHHP_DECODE_MSG
{
DWORD dwStructSize; // Size of decode
structure.
TCHAR ...
|
by: Peter Row |
last post by:
Hi,
I know this has been asked before, but reading the threads it is still not
entirely clear.
Deciding which .Replace( ) to use when.
Typically if I create a string in a loop I always use a...
|
by: Richard Lewis Haggard |
last post by:
I thought that the whole point of StringBuilder was that it was supposed to
be a faster way of building strings than string. However, I just put
together a simple little application to do a...
|
by: m00nm0nkey |
last post by:
Ok well i thought i'd try a different approach, so what I'm now trying is
appending 50,000 lines from the collection to a stringbuilder, and then
writing that entire stringbuilder to a file.
...
|
by: Jure Bogataj |
last post by:
Hello!
Does anybody knows how to handle this issue:
I have an Delphi DLL with following two function declaration:
function DeallocateString(lpszString : PChar) : DWORD; stdcall;
function...
|
by: raylopez99 |
last post by:
StringBuilder better and faster than string for adding many strings.
Look at the below. It's amazing how much faster StringBuilder is than
string.
The last loop below is telling: for adding...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |