By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

segmentation fault, memory problem ?

P: n/a
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

Sep 20 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
S S

vf***@talktalk.net wrote:
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.

Sep 20 '06 #2

P: n/a
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 ?

Sep 20 '06 #3

P: n/a
vf***@talktalk.net wrote:
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.
Sep 20 '06 #4

P: n/a
Jacek Dziedzic schrieb:
[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
HTH,
- J.
Sep 20 '06 #5

P: n/a
Can't I tell the compiler to allow more memory ? Why do I have to
program it ?

Sep 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.