-1
SIZE = 2*1024*1024*1024;
struct
{
   char array[SIZE];
} s1;
char *seq;
File *sp;
int i = 0;
EoFReached = 0;
memset(array,0,SIZE*sizeof(char));
while(EoFReached == 0) {
    getseq(sp, seq, EoFReached);
    memcpy(&(s1->array[i]),seq, seqlen);
    i = i + seqlen;
}

After i value of 630511104 memcpy overwrites some values with some wrong values in the beginning of the array itself but at same time ending values are correct.

So tired to allocate memory dynamically instead of static allocation, using malloc.

But got segmentation falut after 630511104 with error message in gdb as

__memcpy_ssse3 () at ..sysdeps/x86_64/multiarch/memcpy-ssse3.S:" ../sysdeps/x86_64/multiarch/memcpy-ssse3.S: No such file or directory.

bsp
  • 1
  • 1
  • 3

1 Answers1

0

You put the 2 gig big s1 on the stack wich is not that big. Try to allocate s1 with new instead:

struct fred { char array[SIZE]; }; fred * s1 = new fred;
jorg
  • 1
  • we did the same thing using malloc, but we got segmentation fault – bsp Apr 10 '15 at 12:20
  • I don't see anything wrong. In this situation I usually use the program valgrind, which runs your program in debug mode (factor 30 slower) and checks all memory access. – jorg Apr 13 '15 at 14:11
  • Should it be memcpy(&(s1.array[i]),seq, seqlen); instead of memcpy(&(s1->array[i]),seq, seqlen); ? – jorg Apr 14 '15 at 14:23