kalvina@ACF8.NYU.EDU (Alan Kalvin) (01/05/90)
If malloc is used to allocate an amount of memory greater or equal to the system page size, will the memory returned will be page-aligned? If not, is it possible to force page-alignment? Any ideas/suggestions will be appreciated. --------------------------------------- Alan Kalvin (Internet: kalvina@acf8.nyu.edu) NYU Robotics Laboratory 719 Broadway, New York, NY 10003 TEL: (212) 998-3471
davea@quasar.wpd.sgi.com (David B. Anderson) (01/05/90)
In article <9001041731.AA03346@acf8.NYU.EDU> kalvina@ACF8.NYU.EDU (Alan Kalvin) writes: > >If malloc is used to allocate an amount of memory greater or equal to >the system page size, will the memory returned will be page-aligned? No, not by default. And not with the libc.a malloc. >If not, is it possible to force page-alignment? Look at the mallinfo man page (M_GRAIN particularly). Appropriately configured and used, the malloc in libmalloc.a will do what you want. Regards, [ David B. Anderson Silicon Graphics (415)335-1548 davea@sgi.com ] PS: The traditional (before mallinfo()) way to do this is to a) malloc 1 page more than is needed. b) adjust the returned pointer (upwards) to the nearest page boundary. The extra space is ``wasted''. Moreover, the adjusted pointer cannot be used in a free(3) call (only the original pointer can be used with free() ).