Well, this is my first topic at this forum and I'm a newbie on C programming too.
I'm coding a little program and I've used some "dynamic arrays" on it. Compiling and running the program on Linux worked fine for me. But I was very curious to see how the program runs on Windows, so I decided to test it. Compilation was fine too, but when I run the program, I get a memorry allocation error.
Here's the code:
That is the part. I compiled it and when I run it I get the message "Memory error while saving temp text data!"
On Linux I was using the gcc compiler. On Windows, I'm using Dev-C++ 4.9.9.2 with Mingw/GCC 3.4.2.
Ss I said, it is compiled on Windows, but I get the memory error when try to run.
I think that it's because of the differences between Windows/Linux memory allocation and need to say that my program uses "a lot of memory" (more especificaly, something about 25MiB).
So, why did it occurs? It's because of the "malloc/realloc" inside a big loop?
Thanks for the answers.
I'm coding a little program and I've used some "dynamic arrays" on it. Compiling and running the program on Linux worked fine for me. But I was very curious to see how the program runs on Windows, so I decided to test it. Compilation was fine too, but when I run the program, I get a memorry allocation error.
Here's the code:
Code:
int *tspos, *tepos = NULL; int tcc = 0; . . . // the following loop loops about 30000 times // and saves the beggining and the ending position // of some texts loop() { if((tspos=(int *)realloc(tspos,(tcc+1)*sizeof(int)))==NULL) error("Memory error while saving temp text data!\n"); if((tepos=(int *)realloc(tepos,(tcc+1)*sizeof(int)))==NULL) error("Memory error while saving temp text data2!\n"); tspos[tcc]=spos; tepos[tcc]=epos; tcc++; }
That is the part. I compiled it and when I run it I get the message "Memory error while saving temp text data!"
On Linux I was using the gcc compiler. On Windows, I'm using Dev-C++ 4.9.9.2 with Mingw/GCC 3.4.2.
Ss I said, it is compiled on Windows, but I get the memory error when try to run.
I think that it's because of the differences between Windows/Linux memory allocation and need to say that my program uses "a lot of memory" (more especificaly, something about 25MiB).
So, why did it occurs? It's because of the "malloc/realloc" inside a big loop?
Thanks for the answers.
Comment