Maximum memory for string ? . System.MemoryOutOfException Occurs when reading the Content of the file and Storing it in a string.

Last post 10-20-2009 6:28 AM by balajicodeit. 0 replies.

Sort Posts:

  • Maximum memory for string ? . System.MemoryOutOfException Occurs when reading the Content of the file and Storing it in a string.

    10-20-2009, 6:28 AM
    • Member
      point Member
    • balajicodeit
    • Member since 10-20-2009, 5:47 AM
    • Posts 1

    Hi,

    I have a C++ code which reads a file [vtk file - its similar to text file only]. and try to store it in string.

    here's the code:

    String^ ParallelProjectionRenderer::GetVolumeDataAsString(String^ FileName)

    {
        vtkSmartPointer<vtkDataSetWriter> sWriter = vtkSmartPointer<vtkDataSetWriter>::New();

        String^ FileName = "D:\\Users\\...";

        char * sptName = static_cast<char *>(Marshal::StringToHGlobalAnsi(FileName).ToPointer());

        sWriter->SetFileName(sptName);

        sWriter->Register(nullptr);

        sWriter->SetInput(this->dataSource);

        sWriter->SetFileTypeToASCII();

        sWriter->Write();

        sWriter->Delete();

        String^ result= File::ReadAllText(FileName);   [it breaks here with system.memoryoutofexception when the file size is huge]

        return result;

    }

    this code executes fine when the file size is less than 8mb.

    I wanted to know whats the maximum memory allocated to the string.


    As a workaround i skipped reading out in C++ code. and i tried to read the file contents in asp.net C# code and store it on string.

    Same sort of exception came.


    Basically i need this result in string bcoz, I need to communicate with the Silverlight component.

    As far as i know, the WebForm to silverlight communication is done via javascript using string message.

    So is there a way for this issue?



    Thanx in advance,

    Balajee





Page 1 of 1 (1 items)