Re: large struct cause segmentation fault
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 16:13:15 +1200
Aloha wrote:
Hi, everybody:Works fine on my Solaris laptop with Sun Studio.
I am puzzled by the segmentation fault caused by a large struct
malloced in my program, see below the actual code, the program will
cause segmentation fault when I try to acess bb->xyz[20[1000], I am
running on solaris 2.8 using gcc 2.8.1, and other than the stack size
is limited to 8M, all other resources such as virtural memory are
unlimited, my physical memory is 256M, my virtual memory is more than
1G.
So, what is wrong?
Regardsmissing <stdlib.h>
/* code begins */
#include <stdio.h>
typedef struct abc {
char efg[128][1024*1024];
char ijk[128][1024*1024];
char xyz[128][1024*1024];
} ABC;
main()int main()
{
ABC *bb = 0;
bb = (ABC *)malloc(sizeof(ABC));
printf("access head of ABC\n");
bb->ijk[0][0] = 0; /* this is ok */
printf("acces head ok.\n");
printf("access tail of ABC\n");
bb->xyz[20][1000] = 0; /*crash here */
printf("acces tail ok.\n");
}
/* code ends */
Isn't that rather obvious?
--
Ian Collins.
.
- Follow-Ups:
- Re: large struct cause segmentation fault
- From: Aloha
- Re: large struct cause segmentation fault
- References:
- large struct cause segmentation fault
- From: Aloha
- large struct cause segmentation fault
- Prev by Date: Re: `command`
- Next by Date: Re: large struct cause segmentation fault
- Previous by thread: Re: large struct cause segmentation fault
- Next by thread: Re: large struct cause segmentation fault
- Index(es):
Relevant Pages
|