Re: large struct cause segmentation fault



Aloha wrote:
Hi, everybody:

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?

Works fine on my Solaris laptop with Sun Studio.

Regards

/* code begins */

#include <stdio.h>

missing <stdlib.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.
.



Relevant Pages

  • forcing the compiler to reload from memory with c++0x
    ... using a thread fence (I don't really have a memory ordering issue here ... template <typename T, int N> ... int tail = writer_.tail; ... int head = reader_.head; ...
    (comp.programming.threads)
  • large struct cause segmentation fault
    ... I am puzzled by the segmentation fault caused by a large struct ... unlimited, my physical memory is 256M, my virtual memory is more than ... typedef struct abc { ... printf("access tail of ABC\n"); ...
    (comp.unix.programmer)
  • Re: Restoring a NorthStar Horizon, problems with SRAM board
    ... assembler source for that ROM only monitor you mentioned earlier? ... When the head positioner comes out of the spiral grove, ... groove" on it's own - usually it gets knocked out). ... A-D FDC is a memory mapped IO device so I would expect some behavior ...
    (comp.sys.northstar)
  • Re: Panasonic kx-p1123
    ... To work properly as a graphics printer, a dot matrix printer must have ... printing head. ... memory to do this, ... I posted a question previously about two dot matrix printers. ...
    (microsoft.public.windows.vista.print_fax_scan)
  • Re: Its Finally Done
    ... > stuff to a too-bare framework which was written in a hurry a year ... I can't keep a whole book in my head without some kind of diagrammatic ... memory, but creating the aide memoire tends to reinforce what memory ...
    (rec.arts.sf.composition)