E
Eyegor
I have a question about malloc function.
I have a function AEI_malloc() which basically returns a pointer to an
array that it malloced.
I have the following code:
A=AEI_malloc();
B=AEI_malloc();
C=AEI_malloc();
where A, B and C are properly defined pointers. This code compiles and
runs on my machine. But if I try to compile it and run it on a
different machine, it still compiles ok but i get a memory error
running it. I solved the problem by doing this:
A=AEI_malloc();
/*Do some stuff like cycle through A and assign it all 0s. A is 1024
element array*/
B=AEI_malloc();
/*Do some stuff like cycle through B and assign it all 0s. B is 1024
element array*/
C=AEI_malloc();
So basically I add a "pause" between malloc function calls.
Is there a reason why this would happen? I do check for malloc failure
inside of AEI_malloc() function, so in 1st case AEI_malloc for B fails
on B, its not that it failed on A and then B...
AEI_malloc() basically looks up some predefined constants and sets up
some default values for the allocated space. A, B, and C are pointers
to structures with array and 2 integers, so AEI_malloc() sets up
values of the integer portions of the structure which was allocated
and pointer to which gets returned by AEI_malloc()
Thanks ahead.
I have a function AEI_malloc() which basically returns a pointer to an
array that it malloced.
I have the following code:
A=AEI_malloc();
B=AEI_malloc();
C=AEI_malloc();
where A, B and C are properly defined pointers. This code compiles and
runs on my machine. But if I try to compile it and run it on a
different machine, it still compiles ok but i get a memory error
running it. I solved the problem by doing this:
A=AEI_malloc();
/*Do some stuff like cycle through A and assign it all 0s. A is 1024
element array*/
B=AEI_malloc();
/*Do some stuff like cycle through B and assign it all 0s. B is 1024
element array*/
C=AEI_malloc();
So basically I add a "pause" between malloc function calls.
Is there a reason why this would happen? I do check for malloc failure
inside of AEI_malloc() function, so in 1st case AEI_malloc for B fails
on B, its not that it failed on A and then B...
AEI_malloc() basically looks up some predefined constants and sets up
some default values for the allocated space. A, B, and C are pointers
to structures with array and 2 integers, so AEI_malloc() sets up
values of the integer portions of the structure which was allocated
and pointer to which gets returned by AEI_malloc()
Thanks ahead.