A bug in String.ToCharArray?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Barnes

    A bug in String.ToCharArray?

    I have encountered what appears to be a bug in
    String.ToCharAr ray, 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 ConsoleApplicat ion1
    {
    class Class1
    {
    [STAThread]
    static void Main(string[] args)
    {
    string buffer = new string ( 'M', 12581653 );
    char [] chs = buffer.ToCharAr ray ();
    Console.WriteLi ne ( "chs Length = {0}",chs.Lengt h );
    }
    }
    }

    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.
  • Wiktor Zychla

    #2
    Re: A bug in String.ToCharAr ray?

    > I have encountered what appears to be a bug in[color=blue]
    > String.ToCharAr ray, 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:[/color]

    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


    Comment

    • Michael B.

      #3
      Re: A bug in String.ToCharAr ray?

      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!

      Comment

      • Gang Peng[MSFT]

        #4
        Re: A bug in String.ToCharAr ray?

        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]

        Comment

        • Michael B.

          #5
          Re: A bug in String.ToCharAr ray?

          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!

          Comment

          • Gang Peng

            #6
            Re: A bug in String.ToCharAr ray?

            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.ad dress@all> wrote in message
            news:e%23%23m%2 3higDHA.1088@TK 2MSFTNGP10.phx. gbl...[color=blue]
            > 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![/color]


            Comment

            • Michael B.

              #7
              Re: A bug in String.ToCharAr ray?

              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!

              Comment

              • Michael B.

                #8
                Re: A bug in String.ToCharAr ray?

                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!

                Comment

                Working...