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).
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.
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)
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.
Join our real-time social learning platform and learn together with your friends!