unexplainable segfaults

M

Marc R.

Hi there,

consider the following code:

#include "stdafx.h"
int main(int argc, char* argv[]) {
const int Xres = 600;
const int Yres = 600;
std::pair<float,float> dispFNabla[Yres][Xres];
std::pair<float,float> dispFNabla2[Yres][Xres];
std::pair<float,float> dispFNabla3[Yres][Xres];
std::pair<float,float> dispFNabla4[Yres][Xres];
std::pair<float,float> dispFNabla5[Yres][Xres];
std::pair<float,float> dispFNabla6[Yres][Xres];
std::pair<float,float> dispFNabla7[Yres][Xres];
std::pair<float,float> depthFNablaZ[Yres][Xres];
float depthHessZ[Yres][Xres][4];
return 0;
}

Why in the world could it generate a segmentation fault? :

(gdb) run
Starting program: /local/home/neo/BT/P/MicroDepth
Failed to read a valid object file image from memory.

Program received signal SIGSEGV, Segmentation fault.
0x08048e0c in main () at src/MicroDepth.cxx:6
6 std::pair<float,float> dispFNabla[Yres][Xres];
(gdb) print dispFNabla
$1 = {{{first = 0, second = 0} <repeats 600 times>} <repeats 599
times>, {{
first = 0, second = 0} <repeats 277 times>, {first =
-2.67723372e-05,
second = -1.70868349}, {first = -2.89307955e-05,
second = -2.45322353e-05}, {first = -2.6772359e-05,
<snip>
second = 1.40129846e-45}...}}
(gdb) print dispFNabla2
$2 = {{{first = 0, second = 0} <repeats 600 times>} <repeats 600
times>}
(gdb) print dispFNabla3
Cannot access memory at address 0xbf66030c
(gdb) print dispFNabla4
Cannot access memory at address 0xbf3a110c

Regards,
Marc
 
I

Ian Collins

Marc said:
Hi there,

consider the following code:

#include "stdafx.h"

What's this?
int main(int argc, char* argv[]) {
const int Xres = 600;
const int Yres = 600;
std::pair<float,float> dispFNabla[Yres][Xres];
std::pair<float,float> dispFNabla2[Yres][Xres];
std::pair<float,float> dispFNabla3[Yres][Xres];
std::pair<float,float> dispFNabla4[Yres][Xres];
std::pair<float,float> dispFNabla5[Yres][Xres];
std::pair<float,float> dispFNabla6[Yres][Xres];
std::pair<float,float> dispFNabla7[Yres][Xres];
std::pair<float,float> depthFNablaZ[Yres][Xres];
float depthHessZ[Yres][Xres][4];
return 0;
}

Why in the world could it generate a segmentation fault? :
Overflowed your stack?
 
S

Sylvester Hesp

Default User said:
Marc said:
Hi there,

consider the following code:
float depthHessZ[Yres][Xres][4];
Cannot access memory at address 0xbf3a110c

Almost 1.5 meg of automatic data? I'm not surprised. Use a vector or
dynamic array.

1.5? For that one definition, yes. But you forgot a few:
std::pair<float,float> dispFNabla[Yres][Xres];
std::pair<float,float> dispFNabla2[Yres][Xres];
std::pair<float,float> dispFNabla3[Yres][Xres];
std::pair<float,float> dispFNabla4[Yres][Xres];
std::pair<float,float> dispFNabla5[Yres][Xres];
std::pair<float,float> dispFNabla6[Yres][Xres];
std::pair<float,float> dispFNabla7[Yres][Xres];

That's about 23.3 megs in total, assuming 4 bytes per float and 8 bytes per
std::pair<float, float>, which seems a pretty reasonable assumption :)

- Sylvester
 
H

Howard

Ian Collins said:
What's this?

That's a header file automatically generated for you when creating a new
Visual C++ project. It sets some platform-related macro values, and
#includes windows.h.

I suspect most novices don't pay any attention to it at all. I usually
remove it (and set the project to not use precompiled headers).

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

save(char* filename) 5
displaying output from this program 2
Chatbot 0
TF-IDF 2
segmentation fault sometimes 6
Tasks 1
Questions about new range for 2
Vecotor of Pairs 8

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top