473,770 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array size (?)

hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???
Nov 14 '05 #1
11 2228
tw*********@yah oo.com (mike) writes:
i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???


You probably screwed up memory allocation or access. Try a
memory debugger like valgrind.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2
j

"mike" <tw*********@ya hoo.com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???


If you are unable to trace, you have probably corrupted your stack
by using an array with automatic storage duration that is too large.

What is the size of your array? Under c89 the size of the largest object
that can be created is 32767 bytes and 65535 bytes under c99.

--
j
Nov 14 '05 #3
In 'comp.lang.c', tw*********@yah oo.com (mike) wrote:
hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???


I guess it's a local array. This happens. The C language isn't clear about
local variables size limitations. Sounds to be an implementation issue.

The naive way : add 'static' before the definition of the array.
The better way : use dynamic allocation (malloc() / free())

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #4
"j" <ja**********@b ellsouth.net> writes:
"mike" <tw*********@ya hoo.com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???


If you are unable to trace, you have probably corrupted your stack
by using an array with automatic storage duration that is too large.

What is the size of your array? Under c89 the size of the largest object
that can be created is 32767 bytes and 65535 bytes under c99.


Those are minimum maxima. A C89 implementation is allowed to limit
object sizes to 32767 bytes, but it can supporter larger objects (and
most implementations do); likewise for C99 and 65535.

Some operating systems may provide ways to adjust memory allocation
limits. There may also be different limits for declared objects
vs. heap-allocated objects.

(Since this is comp.lang.c, not comp.unix.progr ammer, it would be
inappropriate to mention the "limit" or "ulimit" command, so I won't.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
mike wrote:
I am running a very big code on my pc using RedHat Linux.
When I try to increase my array size, compile and run, I get
segmentation fault. I go into the debugger, run it, it crashes
right away. I can't even trace where it happens.
I have no idea what is the problem. Any idea? cat main.c #include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
char a[16*1024*1024];
const
size_t n = 16*1024*1024;
for (size_t j = 0; j < n; ++j)
a[j] = '\0';
fprintf(stdout, "Hello world!\n");
return 0;
}
gcc -Wall -std=c99 -pedantic -o main main.c
./main Segmentation fault (core dumped) rm core.30147
limit stacksize stacksize 10240 kbytes limit stacksize 20240
limit stacksize stacksize 20240 kbytes
Hello world! gcc --version

gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
Nov 14 '05 #6
E. Robert Tisdale wrote:
mike wrote:
I am running a very big code on my pc using RedHat Linux.
When I try to increase my array size, compile and run, I get
segmentation fault. I go into the debugger, run it, it crashes
right away. I can't even trace where it happens.
I have no idea what is the problem. Any idea?


> cat main.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
char a[16*1024*1024];
const
size_t n = 16*1024*1024;
for (size_t j = 0; j < n; ++j)
a[j] = '\0';
fprintf(stdout, "Hello world!\n");
return 0;
}
> gcc -Wall -std=c99 -pedantic -o main main.c
> ./main

Segmentation fault (core dumped)
> rm core.30147
> limit stacksize

stacksize 10240 kbytes
> limit stacksize 20240
> limit stacksize

stacksize 20240 kbytes
./main
Hello world!
> gcc --version

gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)

Nov 14 '05 #7
j

"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
"j" <ja**********@b ellsouth.net> writes:
"mike" <tw*********@ya hoo.com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???
If you are unable to trace, you have probably corrupted your stack
by using an array with automatic storage duration that is too large.

What is the size of your array? Under c89 the size of the largest object
that can be created is 32767 bytes and 65535 bytes under c99.


Those are minimum maxima. A C89 implementation is allowed to limit
object sizes to 32767 bytes, but it can supporter larger objects (and
most implementations do); likewise for C99 and 65535.


Sorry. I meant to include the word ``portably'' after ``created''.
Some operating systems may provide ways to adjust memory allocation
limits. There may also be different limits for declared objects
vs. heap-allocated objects.

(Since this is comp.lang.c, not comp.unix.progr ammer, it would be
inappropriate to mention the "limit" or "ulimit" command, so I won't.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> We must do something. This is something. Therefore, we must do this.

Nov 14 '05 #8
"j" <ja**********@b ellsouth.net> wrote in message news:<Zw******* ************@bi gnews6.bellsout h.net>...
"mike" <tw*********@ya hoo.com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???


If you are unable to trace, you have probably corrupted your stack
by using an array with automatic storage duration that is too large.

What is the size of your array? Under c89 the size of the largest object
that can be created is 32767 bytes and 65535 bytes under c99.


i use C programming to do simulations (solving eqns), so my knowledge of
the language is limited to what my needs are. i needed to mention this so
that you guys don't talk pass me.

ok...i declare all my variables with static array sizes. (a while back,
i did try the dynamic allocations as Emmanuel suggested below, but since there
is a huge number of variables with O(1e5-1e6) degrees of freedom with
complicate relationships, i decided to abandon this). one of my variables:

double q[2650000][10][5] -> this is fine, but when i try:
double q[4530000][10][5] -> here is the error i got from the ddd debugger:

Program received signal SIGSEGV, Segmentation fault.
0x40000be0 in q ()

you guys are right, it looks like the memory is messed up.
so there is a limit on the array size?
Nov 14 '05 #9
"j" <ja**********@b ellsouth.net> wrote in message news:<Zw******* ************@bi gnews6.bellsout h.net>...
"mike" <tw*********@ya hoo.com> wrote in message
news:58******** *************** ***@posting.goo gle.com...
hi,

i am running a very big code on my pc using redhat linux.
when i try to increase my array size, compile and run, i get
segmentation fault. i go into the debugger, run it, it crashes
right away. i can't even trace where it happens.
i have no idea what is the problem. any idea ???


If you are unable to trace, you have probably corrupted your stack
by using an array with automatic storage duration that is too large.

What is the size of your array? Under c89 the size of the largest object
that can be created is 32767 bytes and 65535 bytes under c99.


i use C programming to do simulations (solving eqns), so my knowledge of
the language is limited to what my needs are. i needed to mention this so
that you guys don't talk pass me.

ok...i declare all my variables with static array sizes. (a while back,
i did try the dynamic allocations as Emmanuel suggested below, but since there
is a huge number of variables with O(1e5-1e6) degrees of freedom with
complicate relationships, i decided to abandon this). one of my variables:

double q[2650000][10][5] -> this is fine, but when i try:
double q[4530000][10][5] -> here is the error i got from the ddd debugger:

Program received signal SIGSEGV, Segmentation fault.
0x40000be0 in q ()

you guys are right, it looks like the memory is messed up.
so there is a limit on the array size?
Nov 14 '05 #10

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

Similar topics

13
34397
by: Noah Spitzer-Williams | last post by:
Hello guys, I would like to do something seemingly simple: find out if an element in an array that is passed to my function exists. I used to think I could just do: if (arr) ... However, if this element's value happens to be 0, the conditional will return false, even though the element actually exists. Any ideas? Can you check if the element == null?
58
10181
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
3
2476
by: ritchie | last post by:
Hi all! Still working on this program! Just to recap, I am writing a program to sort an array with four different sort algorythms. I am having a little trouble at the moment though! Now, I am trying to calculate, with each sort, how many times during the sort the array elements are compared and swapped.
8
4615
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line later on. Before that happens there has been a problem that causes a crash of the program. This is a little program "test.exe" I wrote to test what happens. compiler: mingw 3.1.01 for win32 command line
6
4152
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the end is found is less efficient than using sizeof operator , since size of the array is completely determined at compile time. i don't quite understand this. Could anyone explain to me in detail ?
22
2465
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a nightmare. There are of course many solutions, but they all end up forcing you to abandon the array syntax in favour of macros or functions. Now I have two questions - one is historical, and the other practical. 1.) Surely malloc (and...
7
7417
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For example, the manner in which I update element 1 depends on several other (randomly numbered) elements in the array. So, I can't change an element until I've figured out how every element changes.
12
112102
by: manochavishal | last post by:
Hi, I have a question. How can i know the size of array when it is passed to a function. For Example i have this code: #include <stdio.h> #include <stdlib.h>
20
2326
by: Cyn | last post by:
Hi, I want to create a general array structure which can hold all types. Something like this: struct ARRAY { void **array; size_t size; };
28
4581
Nepomuk
by: Nepomuk | last post by:
Hi! I've read, that in C++ there's no predefined method, to calculate the size of an array. However, it's supposed to work withsizeof(array)/sizeof(array)Now, this does work in some situations, but not in others. Here's what I mean:#include <iostream> int length(int * array){return sizeof(array)/sizeof(array);} int main() { int array1 = {3,2,1,0}; std::cout << "Length of array1: " << sizeof(array1)/sizeof(array1) << "\n" <<...
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8891
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.