#exit code 3221225725 (ran out of stack memory)

40 messages · Page 1 of 1 (latest)

narrow solarBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

native dagger
#
    string InputtedScale[n];
#

what are you expecting from this?

coarse musk
#

what do you use for input

native dagger
#

ok. In C++ the size of an array can't be dynamic (unless you create the array with new)

#

what you'd really want to use here is std::vector<int>

coarse musk
#

print out your variable n before the array is created

native dagger
#

no, those are called VLAs and aren't allowed in C++

coarse musk
#

and you will see something insane there

#

a random garbage value, yes

native dagger
#

more than likely it'll end up being 0 as this is near the start of the program

coarse musk
#

your array will not be on the heap, it will be on the stack frame, limited to 2MB

#

do the math

#

and switch to a dnamically allocated data structure instead

#

did you print n like I said

#

before the array

#

if you reboot your machine it can change

#

so, an array with 6.4 million elements

#

stored in the stack frame whose size is 2MB

#

there's not enough space on the stack frame for this

#

get it?

#

each element takes sizeof(string) bytes

#

not enough space in the stack frame, yes

#

use a hardcoded counter, like 100 or something

#

because I know where in memory local variables live, that's why

#

unlike in python where every f*cking thing is in the heap

#

well, set n to be a const too

#

that way the compiler can see that this is a fixed length array

#

and produce more optimised code

native dagger
#

well is n based on the user input? it seems that it is in the code you have right now

#

no. the size of c arrays is fixed

#

and the only way to change it is to create a new array

coarse musk
#

no, once the array is created you can't extend it

native dagger
#

if this is an assignment that limits you to c arrays, then use new[], if you can use other stuff then use std::vector

coarse musk
#

std::vector is the equivalent of a python list

native dagger
#

std::vector is the most used c++ collection and is a dynamic array

hollow vine
#

thats exactly what it is yes

coarse musk
#

the syntax about what

narrow solarBOT
#

This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.