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 3408 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: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
| |