From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,97d3ded662883f7c X-Google-Attributes: gid111c93,public X-Google-ArrivalTime: 2001-01-11 08:09:54 PST Path: supernews.google.com!sn-xit-02!sn-post-01!supernews.com!news.supernews.com!not-for-mail From: Pierre Asselin Newsgroups: comp.os.linux.alpha Subject: Re: weird behavior of malloc() Date: Thu, 11 Jan 2001 16:07:49 -0000 Organization: Rexx Electronic Communications Message-ID: <979229268.387499@rexx.com> References: <93iohn$m3c$1@nnrp1.deja.com> User-Agent: tin/1.5.4-20000523 ("1959") (UNIX) (FreeBSD/4.1.1-STABLE (i386)) Cache-Post-Path: rexx.com!lpa@207.167.89.8 X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/) X-Complaints-To: newsabuse@supernews.com Xref: supernews.google.com comp.os.linux.alpha:1852 rwgk@my-deja.com wrote: > > System: > Red Hat Linux release 6.2 (Zoot) > Kernel 2.2.14-6.0smp on a 2-processor alpha > > On this system, malloc() returns pointers to places in memory that > are very far apart. For example, one call returns 0x125f77510, > and the next one 0x20000002010 (the first call only allocates > 16 bytes or so, the second one about 160000 bytes). If I remember correctly, Gnu malloc uses brk(2) for small chunks and mmap(2) for big chunks. You can change the threshold with mallopt(M_MMAP_THRESHOLD, ). > Unfortunately, this behavior is causing us problems. For use in > a Fortran program, we compute the difference between the pointers > returned by malloc() and a pointer to a Fortran reference array. > The difference is divided by the size of Fortran INTEGER, and > that result passed back from C to Fortran as a Fortran INTEGER. > If the difference is too large for INTEGER, our program crashes. You're between a rock and a hard place. Try mallopt(), but even it it works you'll be sitting on a time bomb. Otherwise, a quick fix would be to replace all INTEGER declarations by INTEGER*8, without bothering at first to check which integers hold memory offsets. If some of those integers are in common, expect trouble. If some are equivalenced, expect big trouble. Another way would be to write your own malloc replacement and use the preprocessor to make your C code use it. The C library (e.g. stdio) would still use the real malloc, but presumable it doesn't pass offsets back to Fortran. > Our program is very large (>100000 lines) and it is practically > impossible to find and replace all INTEGER that store offsets for > dynamic memory allocation. Also, the program is running fine > on another 64-bit architecture (IRIX64). Why does malloc() on > the Alpha return pointers to places in memory that are so far > apart? Could this be changed? On True64, the compilers have a `-taso' flag to force everything in a 32-bit address space, but that requires support from the OS and is not available on Linux. Don't know about Irix. -- Pierre Asselin Westminster, Colorado