+ 7

Segmentation fault (Core dumped)

I have a problem in C. My program generally works good but when I try to make an array with more than 10.000 elements it throw this error. What to do?

23rd Nov 2019, 11:52 AM
Lighton
Lighton - avatar
13 Antworten
+ 12
Lighton if you are getting a segmentation fault then it means that you are trying to access a memory location that is not accessible. Edit: 10000*5000 = 50000000 elements and each occupy 4 bytes of memory so the memory occupied is 200000000 bytes. Do you understand how big is that?
23rd Nov 2019, 12:26 PM
Avinesh
Avinesh - avatar
+ 5
Can you show us the code?
23rd Nov 2019, 11:54 AM
HonFu
HonFu - avatar
+ 5
Ruchika Tripathi your post is irrelevant!
24th Nov 2019, 11:29 PM
Sonic
Sonic - avatar
+ 3
HonFu To be honest I do not know the answer to that but a 200 mb file sounds very big. In general our files are hardly few kilo bytes. I do not exactly know that what part of RAM is allocated for a particular program but I hope to find the answer to that.
23rd Nov 2019, 1:17 PM
Avinesh
Avinesh - avatar
+ 3
Kit D. Cat how does one check for the stack memory on their system? Also thank you for making things clear.
23rd Nov 2019, 1:49 PM
Avinesh
Avinesh - avatar
+ 2
Avinesh, is there some way to know how large these arrays can be? I mean, sure, what is it, 200 mb, is large, but shouldn't a regular pc be able to do it anyway? naive Pythonist -->
23rd Nov 2019, 1:06 PM
HonFu
HonFu - avatar
+ 2
Okay, 8mb is not a lot... So if OP reconfigured the code to using heap space, huge arrays like that would become possible?
23rd Nov 2019, 1:46 PM
HonFu
HonFu - avatar
+ 1
Yes, wait a moment
23rd Nov 2019, 12:00 PM
Lighton
Lighton - avatar
23rd Nov 2019, 12:03 PM
Lighton
Lighton - avatar
+ 1
It's a part of my school excercise. Line 35 is accidentally there so it was not the problem. Can you run it with 10000*5000 elements
23rd Nov 2019, 12:22 PM
Lighton
Lighton - avatar
+ 1
Oh yes, so the problem is in the size of this array. There is no any syntax mistakes, right?
23rd Nov 2019, 12:46 PM
Lighton
Lighton - avatar
0
Remove line 35 and then input 2 array size values. It outputs m×n matrix. But do not understand what you are trying to achieve.
23rd Nov 2019, 12:10 PM
Avinesh
Avinesh - avatar
0
Le problème est dans l'espace mémoire je pense.
25th Nov 2019, 10:12 AM
Barka Abdelghani Yacine
Barka Abdelghani Yacine - avatar