0

I have a large file to read. When I tried to use a 10mb char buffer, I got a stack overflow.

const size_t buffsize = 1024 * 1024 * 10; // 10mb
char buff[buffsize];

Exception thrown at 0x00007FF7FF42D3F7 in ConsoleApplicationTest.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000E352D03000).
Unhandled exception at 0x00007FF7FF42D3F7 in ConsoleApplicationTest.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000E352D03000).

On C#, I used to use over 100mb buffer. So I also tried it on c++ but not worked. There is something I don't know. Please let me know. Thank you.

Eby
  • 43
  • 1
  • 6

1 Answers1

1

Is there a limitation about size of buffer..?

Yes. Computers with infinite memory haven't been invented. There is always a limit.

Stack overflow

Based on the error, we can guess that you used automatic storage for the buffer. The limit for objects in automatic storage is generally much stricter than total memory of the system. It varies between systems but typically defaults to one to few megabytes on server and desktop systems, and that is generally shared between all objects with overlapping automatic storage duration within the same thread.

Use dynamic or static storage for large objects such as this buffer. A simple solution is to use std::vector.

eerorika
  • 232,697
  • 12
  • 197
  • 326