Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

thd_purgedblk.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 Boolean THD_purge_datablock( THD_datablock * blk , int mem_type )
00011 {
00012    int ibr , nfreed ;
00013    void * ptr ;
00014 
00015    /*-- sanity checks --*/
00016 
00017    if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ) return False ;
00018    if( (blk->malloc_type & mem_type) == 0 )             return False ;
00019    if( DBLK_LOCKED(blk) )                               return False ;
00020 
00021    /*-- free the data space --*/
00022 
00023    nfreed = 0 ;
00024    switch( blk->malloc_type ){
00025 
00026       case DATABLOCK_MEM_MALLOC:
00027          for( ibr=0 ; ibr < blk->nvals ; ibr++ ){
00028             ptr = DBLK_ARRAY(blk,ibr) ;
00029             if( ptr != NULL ){ free(ptr) ; nfreed++ ; }
00030             mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00031          }
00032       return True ;
00033 
00034       case DATABLOCK_MEM_MMAP:
00035          ptr = DBLK_ARRAY(blk,0) ;
00036          if( ptr != NULL ){ munmap( ptr , (size_t)blk->total_bytes ) ; nfreed++ ; }
00037          for( ibr=0 ; ibr < blk->nvals ; ibr++ )
00038             mri_clear_data_pointer( DBLK_BRICK(blk,ibr) ) ;
00039       return True ;
00040 
00041       case DATABLOCK_MEM_SHARED:   /* can't be purged */
00042       return False ;
00043    }
00044 
00045    return False ;  /* shouldn't be reached */
00046 }
00047 
00048 /*----------------------------------------------------------
00049    04 May 1998: purge just one sub-brick, if possible
00050 ------------------------------------------------------------*/
00051 
00052 Boolean THD_purge_one_brick( THD_datablock * blk , int iv )
00053 {
00054    void * ptr ;
00055 
00056    /* sanity checks */
00057 
00058    if( ! ISVALID_DATABLOCK(blk) || blk->brick == NULL ) return False ;
00059    if( DBLK_LOCKED(blk) )                               return False ;
00060    if( iv < 0 || iv >= blk->nvals )                     return False ;
00061    if( blk->malloc_type != DATABLOCK_MEM_MALLOC )       return False ;
00062 
00063    ptr = DBLK_ARRAY(blk,iv) ;
00064    if( ptr != NULL ) free(ptr) ;
00065    mri_clear_data_pointer( DBLK_BRICK(blk,iv) ) ;
00066    return True ;
00067 }
 

Powered by Plone

This site conforms to the following standards: