0

I created a VC++ console application (HelloWorld). In that I created one byte array with size 1316779. It's working fine when building the application. Anyway debugging the application it's giving

Unhandled exception at 0x00969167 in HelloWorld.exe: 0xC00000FD: Stack overflow.

But when I changed size to 1010000 then it worked fine.

My requirement is to create a byte array size of 1316779. i.e. byte myArray[1316779];

I am working under XP operating system with Pentium processor and having 2GB RAM.

1
  • Why don't you use a vector? Commented Oct 16, 2014 at 14:34

3 Answers 3

4

1316779 bytes = 1.31 MB

MSVC puts by default a 1 MB stack limit

/F - Without this option the stack size defaults to 1 MB.

You either need to increase that limit or reduce your stack size (e.g. use a heap allocation). I wouldn't rely on 1010000 as well (1.01).

Sign up to request clarification or add additional context in comments.

Comments

1

Define the local array as having static storage duration

static byte myArray[1316779];

Otherwise use standard class std::vector

Comments

0

Obviously, 1316779 bytes are bigger than the stack and you're blowwing it up. So make the 1316779 bytes on the heap and pass a handle to that on the stack:

std::vector<byte> myHugeAmountofBytes;
myHugeAmountofBytes.reserve(1316779);
// put elemnts into myHugeAmountofBytes

myHugeAmountofBytes can now be passed via the stack with no overflow.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.