segmentation fault, memory problem ?

V

vfunc

I have a function "test" in a seperate file to main and a segmentation
fault seems to occur before the first line of the test function is
executed.

void test()
{
DEBUG_LOG("in test");
maca c;
....
}

I am guessing that there is something wrong with maca, which is an
class based on an array of another class which is also based on an
array. O(64x10000) elements altogether. Maybe I need to allocate some
memory in the compilation, or somewhere else ? I can post more details
if neccessary
 
S

S S

I have a function "test" in a seperate file to main and a segmentation
fault seems to occur before the first line of the test function is
executed.

void test()
{
DEBUG_LOG("in test");
maca c;
...
}

I am guessing that there is something wrong with maca, which is an
class based on an array of another class which is also based on an
array. O(64x10000) elements altogether. Maybe I need to allocate some
memory in the compilation, or somewhere else ? I can post more details
if neccessary

If you can replicate it in small code and send us the code would be of
help to debug.
 
V

vfunc

I reduced the size of the array from 100,000 to 1,000 and the fault
disappeared. However I may need to up that new value. So my queston
is how do I reserve a chunk of memory, with g++ directive or someother
way ?
 
J

Jacek Dziedzic

I reduced the size of the array from 100,000 to 1,000 and the fault
disappeared. However I may need to up that new value. So my queston
is how do I reserve a chunk of memory, with g++ directive or someother
way ?

If your array is local, that is probably a stack overflow error.
Try "ulimit -s" and look at the value returned (your maximum
allowed stack size). Use "ulimit" to increase it, or get rid of
the local variable altogether (by allocating it dynamically via new[]).

HTH,
- J.
 
M

Markus Grueneis

Jacek said:
[stack problem description]

If your array is local, that is probably a stack overflow error.
Try "ulimit -s" and look at the value returned (your maximum
allowed stack size). Use "ulimit" to increase it, or get rid of
the local variable altogether (by allocating it dynamically via new[]).

The OP may also consider using std::vector -- then he gets the memory
managment and exception safety for free, and he will have to change less
code than with manual deletes all over the place.

best regards,
-- Markus
 

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

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top