Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

c++ question: Why would the following line of code cause a segfault? float matrixName [1024][1024]; The declaration alone causes a segfault, but only for values > 1020 (ie values < 1020 dont cause a segfault and the program runs correctly).

OpenStudy (rsmith6559):

I wonder what would happen if it was declared at runtime, so it was on the heap, if that would help? I would have to guess that something about your setup isn't happy with 4MB on the stack.

OpenStudy (anonymous):

so there's a memory leak that's causing it. new question: why does ifstream in(currFile); result in a memory leak? (currFile is a string)

OpenStudy (rsmith6559):

No, not really. That syntax would be a stack declaration. The fact that a certain size causes a problem, it would just be interesting to see if the problem persisted on the heap. Memory leaks are memory that's not reclaimed. After in.close(); the memory should be freed, but not before. Actually, I just ran into this a couple of nights ago, it seems that passing in a file name in the declaration also opens the file. I had to take my open() statements out of the program.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!