Doxygen Source Code Documentation
thd_forcemalloc.c
Go to the documentation of this file.00001 /***************************************************************************** 00002 Major portions of this software are copyrighted by the Medical College 00003 of Wisconsin, 1994-2000, and are released under the Gnu General Public 00004 License, Version 2. See the file README.Copyright for details. 00005 ******************************************************************************/ 00006 00007 #include "mrilib.h" 00008 #include "thd.h" 00009 00010 static int native_order = -1 ; 00011 static int no_mmap = -1 ; 00012 00013 void THD_force_malloc_type( THD_datablock *blk , int mem_type ) 00014 { 00015 int new_type ; 00016 00017 no_mmap = AFNI_yesenv("AFNI_NOMMAP") ; 00018 00019 if( native_order < 0 ) native_order = mri_short_order() ; 00020 00021 /*-- sanity checks --*/ 00022 00023 if( ! ISVALID_DATABLOCK(blk) ) return ; 00024 00025 if( mem_type == DATABLOCK_MEM_ANY ){ /* 14 Oct 1996 */ 00026 #if MMAP_THRESHOLD > 0 00027 new_type = (blk->total_bytes > MMAP_THRESHOLD) 00028 ? DATABLOCK_MEM_MMAP : DATABLOCK_MEM_MALLOC ; 00029 #else 00030 new_type = DATABLOCK_MEM_MALLOC ; 00031 #endif 00032 00033 } else { 00034 new_type = mem_type ; 00035 } 00036 00037 if( COMPRESS_filecode(blk->diskptr->brick_name) >= 0 && new_type == DATABLOCK_MEM_MMAP ) 00038 new_type = DATABLOCK_MEM_MALLOC ; 00039 00040 /* 25 April 1998: byte order issues */ 00041 00042 if( blk->diskptr->byte_order <= 0 ) 00043 blk->diskptr->byte_order = native_order ; 00044 else if( blk->diskptr->byte_order != native_order && new_type == DATABLOCK_MEM_MMAP ) 00045 new_type = DATABLOCK_MEM_MALLOC ; 00046 00047 if( no_mmap && new_type == DATABLOCK_MEM_MMAP ) 00048 new_type = DATABLOCK_MEM_MALLOC ; 00049 00050 if( DBLK_LOCKED(blk) ) /* 22 Mar 2001 */ 00051 new_type = DATABLOCK_MEM_MALLOC ; 00052 00053 if( blk->malloc_type == new_type ) return ; 00054 (void) THD_purge_datablock( blk , blk->malloc_type ) ; 00055 blk->malloc_type = new_type ; 00056 00057 DBLK_mmapfix(blk) ; /* 28 Mar 2005 */ 00058 return ; 00059 }