Problem in malloc

Problem in malloc

I am compiling a scientific application on a dual Itanium2, 4GB system (HP zx6000), RedHat Linux 7.2-IA64. Compiler (fortran/C) are Intel compilers v7.0.

The code is mixed fortran77 and C. The fortran code calls C code to do malloc, free and realloc chunks of memory.

I have noticed that when the request size is < 128K (131,072 bytes), the allocation happens (always) in the 6000xxxxxxxxxxxx memory range. The moment the allocation request is for > 128K (say around 160K or 320K), the allocated address is in 2000xxxxxxxxxxx (decimal). This strange behaviour is causing the code to crash. (The code manipulates pointers). To verify I wrote a small C program as follows:

int main(int argc,char *argv[]){
char *p;
int i;

printf("i=%d p=%lX errno=%d

and the output:
i=128000 p=6000000000002970 errno=0
i=129000 p=6000000000002970 errno=0
i=130000 p=6000000000002970 errno=0
i=131000 p=6000000000002970 errno=0
i=132000 p=200000000041C010 errno=0
i=133000 p=200000000041C010 errno=0

See how the address changes completely? This seems to happen only on Itanium (1,2). I do not see such behaviour on Tru64Unix/Alpha21164, Solaris/Sparc64 etc and my application runs fine.

Can anyone help explain?


2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I suppose that you are using the default glibc malloc(); further, that it chooses whether to use stack or heap according to the size of the request. If you are using code which is sensitive to such implementation details, it is clearly non-portable.

Since you aren't using g77, it's not clear why you would avoid using Fortran's own memory allocation.

Leave a Comment

Please sign in to add a comment. Not a member? Join today