473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

segmentation fault, memory problem ?

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
5 2272
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
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
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
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
Can't I tell the compiler to allow more memory ? Why do I have to
program it ?

Sep 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Adi | last post by:
hi guys, i have a weird problem with printf statement. I have a function which just prints a string literal. In my program this function will be called > 2000 times. I get a segmentation fault...
6
by: damian birchler | last post by:
If I run the following I get a segmentation fault: #define NAMELEN 15 #define NPERS 10 typedef struct pers { char name; int money; } pers_t;
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
6
by: I_have_nothing | last post by:
Hi! I am new in C. I try to use dynamical allocation fuction malloc( ) and realloc( ). I found something strange. After several calling realloc( ), the malloc( ) will give me a Segmentation...
18
by: Digital Puer | last post by:
Hi, I'm coming over from Java to C++, so please bear with me. In C++, is there a way for me to use exceptions to catch segmentation faults (e.g. when I access a location off the end of an array)?...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
1
by: andrew browning | last post by:
can someone tell me what a segmentation fault is???? does it mean i am dividing by 0 somewhere?
6
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on...
8
by: Andrea | last post by:
I wrote this code: void * xmalloc (size_t size){ register void *value = OPENSSL_malloc(size); if (value == 0) printf("virtual memory exhausted"); return value; } int _chooseTSK(char*...
3
by: jr.freester | last post by:
I have created to classes Matrix and System. System is made up of type matrix. ---------------------------------------------------------------------------------- class Matrix { private: int...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.