473,320 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

A bug in String.ToCharArray?

I have encountered what appears to be a bug in
String.ToCharArray, and so far I have not found any
mention or discussion about it. I am interested to know
if anyone else is encountering this problem. I am
using .NET framework 1.1, and Visual Studio 2003. I can
reproduce the problem with a simple C# program:

using System;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string buffer = new string ( 'M', 12581653 );
char [] chs = buffer.ToCharArray ();
Console.WriteLine ( "chs Length = {0}",chs.Length );
}
}
}

This will throw an "out of memory" exception on the
ToCharArray call. I actually encountered this problem
trying to parse a large XML fragment - XmlTextReader uses
ToCharArray internally, as does XmlDocument, and both
will crash when presented with an Xml string 12,581,653
characters long.

Interestingly, the act of calling ToCharArray as above
adds about 500MB to the VM Size of my app, as shown in
Task Manager.
Nov 15 '05 #1
7 4398
> I have encountered what appears to be a bug in
String.ToCharArray, and so far I have not found any
mention or discussion about it. I am interested to know
if anyone else is encountering this problem. I am
using .NET framework 1.1, and Visual Studio 2003. I can
reproduce the problem with a simple C# program:


Michael,

I can confirm the problem on my machine. interestingly, the problem DOES NOT
occur under .NET 1.0. it seems that something was broken in .NET 1.1.

I hope someone from MS will finaly read this and at least confirm the
problem.

Regards,
Wiktor
Nov 15 '05 #2
Thanks for verifying that for me, Wiktor. I have reported it to
Microsoft as an "error in their documentation" :-) Hopefully that will
bring it to somebody's attention!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
This is a known bug in GC. We will fail to allocate objects of certain
size.
The formula used to judge if a segment will be enough for an object was
wrong.
You can work around the problems the allocating a larger object (I
understand that's lame.)
If this is blocking you, please contact PSS to get a QFE.

Thanks,
Gang Peng
[MS]

Nov 15 '05 #4
Thank you, Gang Peng. I am glad that you are already on top of the
problem. I have taken the approach you suggested to work around the
problem - in my case, if the XML string that I am trying to parse falls
into the critical length, I just append some additional spaces to the
end. I agree that it is a bit of a rough fix, but it will do for the
time being.

Can you say what release of .NET will incorporate the GC bug fix?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5
Hi, Michael,
I checked the status of this bug with my team member who fixed this.
It is fixed as a QFE in August.
I can find the link to download the QFE tomorrow if you need it.

Gang Peng
[MSFT]
"Michael B." <not.my.real.address@all> wrote in message
news:e%********************@TK2MSFTNGP10.phx.gbl.. .
Thank you, Gang Peng. I am glad that you are already on top of the
problem. I have taken the approach you suggested to work around the
problem - in my case, if the XML string that I am trying to parse falls
into the critical length, I just append some additional spaces to the
end. I agree that it is a bit of a rough fix, but it will do for the
time being.

Can you say what release of .NET will incorporate the GC bug fix?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #6
Thank you, but I don't want to rely on my customers having the right QFE
installed, so I will just leave the code work-around in place.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #7
Thank you, but I don't want to rely on my customers having the right QFE
installed, so I will just leave the code work-around in place.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: registered user | last post by:
I'm trying to take a string, from a JOptionPane and change it into a char array in which I can manipulate the characters as ASCII with other char arrays and append into a new string. I've declared...
5
by: Johnny Meredith | last post by:
Is there a function in VBA to convert a string to an array of characters. I'm looking for the exact same functionality as the ToCharArray() method in C#. If this functionality does not exist, do...
20
by: Peteroid | last post by:
How the heck does one convert a String* to char? Specifically: String* my_string = "HELLO" ; char m_char_array ; m_char_array = my_string ; // error strcpy( m_char_array, my_string ) ; //...
8
by: Frank R Eid | last post by:
Hi all; A) What's the simplest way to convert a 'String' to 'char *' (and the other way araound) ? B) I have some C++ classes that I cannot easily convert to .NET (because they still are...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
2
by: PioM | last post by:
namespace System { public class Text { public static System.Char Omin='\t',Next=' ',Wciecie='\"',Zamkniecie='\"',Null='\0',Object='ÿ'; public static System.Int32 NextCharacter(System.Int32...
6
by: Paulers | last post by:
Hello, I have a string that I am trying to add each char to a datatable row. for example if I have a string that looks like "abcdefg", I would like to break it up into an array of characters...
2
by: bmerlover | last post by:
I want to parse out a string in Visual Studio .NET 2003 in C++. This is the format of the string: T1 = "Hello" It comes from a script file which I load into my gui app. It loads fine and I am...
4
by: Scotty | last post by:
Hi everyone, Is there an equivalent to vb6 Dim test as String * 40 ? I have been looking for a solution but no luck until now. Any help would be greatly appreciated.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.