void WPJGC::GC() { #if GC_TYPE == GC_OPEN U_INT gcCount = 0; foreach_in_list(WPJObject*, itor, m_GCList) { if (m_gcLimit && gcCount > m_maxGcCount) { WPJLOG("[%s] GC 回收达最大限制,暂停回收\n", __TIME__); break; } if (ptr_data(itor)->GetReference() == 1) // Ref = 1, only gc used { WPJLOG("[%s] GC ... %u Bytes Complete!\n", __TIME__, ptr_data(itor)->GetSize()); ++gcCount; ptr_data(itor)->Release(); // Ref = 0, delete itor = m_GCList.erase(itor); } else itor++; } // WPJLOG("[%s] GC ... Once Complete!\n",_D_NOW_TIME__); #endif }
/***********************************************************************//** * @brief Save table column into FITS file * * @exception GException::fits_hdu_not_found * Specified HDU not found in FITS file. * @exception GException::fits_error * Error occured during writing of the column data. * * The table column is only saved if it is linked to a FITS file and if the * data are indeed present in the class instance. This avoids saving of data * that have not been modified. * * The method make use of the virtual methods * GFitsTableCol::ptr_data and * GFitsTableCol::ptr_nulval. * These methods are implemented by the derived column classes which * implement a specific storage class (i.e. float, double, short, ...). ***************************************************************************/ void GFitsTableCol::save_column_fixed(void) { // Continue only if a FITS file is connected and data have been loaded if (FPTR(m_fitsfile)->Fptr != NULL && m_colnum > 0 && ptr_data() != NULL) { // Move to the HDU int status = 0; status = __ffmahd(FPTR(m_fitsfile), (FPTR(m_fitsfile)->HDUposition)+1, NULL, &status); if (status != 0) { throw GException::fits_hdu_not_found(G_SAVE_COLUMN_FIXED, (FPTR(m_fitsfile)->HDUposition)+1, status); } // Save the column data status = __ffpcn(FPTR(m_fitsfile), m_type, m_colnum, 1, 1, m_size, ptr_data(), ptr_nulval(), &status); if (status != 0) { std::string msg = "Unable to save column '"+name()+"' to" " FITS file."; throw GException::fits_error(G_SAVE_COLUMN_FIXED, status, msg); } } // endif: FITS file was connected // Return return; }
/***********************************************************************//** * @brief Load fixed-length column from FITS file * * @exception GException::fits_hdu_not_found * Specified HDU not found in FITS file. * @exception GException::fits_error * An error occured while loading column data from FITS file. * * If a FITS file is attached to the column the data are loaded into memory * from the FITS file. If no FITS file is attached, memory is allocated * to hold the column data and all cells are set to 0. * * The method makes use of the virtual methods * GFitsTableCol::alloc_data, * GFitsTableCol::init_data, * GFitsTableCol::ptr_data, and * GFitsTableCol::ptr_nulval. * These methods are implemented by the derived column classes which * implement a specific storage class (i.e. float, double, short, ...). ***************************************************************************/ void GFitsTableCol::load_column_fixed(void) { // Calculate size of memory m_size = m_number * m_length; // Load only if the column has a positive size if (m_size > 0) { // Allocate and initialise fresh memory alloc_data(); init_data(); // If a FITS file is attached then try loading column data from the // FITS file. This may fail in case that no data has yet been written // to the FITS file. In that case we just skip loading and return // the initalised column ... if (FPTR(m_fitsfile)->Fptr != NULL) { // Move to the HDU int status = 0; status = __ffmahd(FPTR(m_fitsfile), (FPTR(m_fitsfile)->HDUposition)+1, NULL, &status); // If this failed because: // - the primary HDU was not found (status 252) // - we moved past the file (status 107) // we assume that no data have yet been written to the file and // we skip the loading. if (status != 252 && status != 107) { // Break on any other cfitsio error if (status != 0) { throw GException::fits_hdu_not_found(G_LOAD_COLUMN_FIXED, (FPTR(m_fitsfile)->HDUposition)+1, status); } // Load data status = __ffgcv(FPTR(m_fitsfile), m_type, m_colnum, 1, 1, m_size, ptr_nulval(), ptr_data(), &m_anynul, &status); if (status != 0) { throw GException::fits_error(G_LOAD_COLUMN_FIXED, status, "for column '"+m_name+"'."); } } // endif: no primary HDU found } // endif: there was a FITS file attached } // endif: column has a positive size // Return return; }
/***********************************************************************//** * @brief Save table column into FITS file * * @exception GException::fits_hdu_not_found * Specified HDU not found in FITS file. * @exception GException::fits_error * Error occured during writing of the column data. * * The table column is only saved if it is linked to a FITS file and if the * data are indeed present in the class instance. This avoids saving of data * that have not been modified. * * The method make use of the virtual methods * GFitsTableCol::ptr_data and * GFitsTableCol::ptr_nulval. * These methods are implemented by the derived column classes which * implement a specific storage class (i.e. float, double, short, ...). ***************************************************************************/ void GFitsTableCol::save_column_variable(void) { // Continue only if a FITS file is connected and data have been loaded if (FPTR(m_fitsfile)->Fptr != NULL && m_colnum > 0 && ptr_data() != NULL) { // Move to the HDU int status = 0; status = __ffmahd(FPTR(m_fitsfile), (FPTR(m_fitsfile)->HDUposition)+1, NULL, &status); if (status != 0) { throw GException::fits_hdu_not_found(G_SAVE_COLUMN_VARIABLE, (FPTR(m_fitsfile)->HDUposition)+1, status); } // Save the column data row-by-row for (int row = 0; row < m_length; ++row) { // Save row data status = __ffpcn(FPTR(m_fitsfile), std::abs(m_type), m_colnum, row+1, 1, elements(row), ptr_data(m_rowstart[row]), ptr_nulval(), &status); if (status != 0) { std::string msg = "Unable to save row "+gammalib::str(row+1)+"" " of column '"+name()+"' to FITS file."; throw GException::fits_error(G_SAVE_COLUMN_VARIABLE, status, msg); } } // endfor: looped over rows } // endif: FITS file was connected // Return return; }
WPJGC::~WPJGC() { #if GC_TYPE == GC_WATCH CheckMemoryLeak(); #endif #if GC_TYPE == GC_OPEN // release all object int tGCnum; do { tGCnum = 0; foreach_in_list(WPJObject*, itor, m_GCList) { if (pp(itor)->GetReference() == 1) { WPJ_SAFE_RELEASE(pp(itor)); itor = m_GCList.erase(itor); tGCnum++; } else itor++; } } while (tGCnum != 0); foreach_in_list_auto(WPJObject*, itor, m_GCList) { while (ptr_data(itor) && pp(itor)->GetReference() > 1) // m_uRef = 1 ptr_data(itor)->Release(); WPJ_SAFE_RELEASE(ptr_data(itor));// m_uRef = 0 } #endif // GC_OPEN m_GCList.clear(); }
void WPJGC::CheckMemoryLeak() { SetLimit(false); GC(); U_INT leakSize = 0; U_INT poolSize = 0; foreach_in_list_auto(WPJObject*, itor, m_GCList) { if (ptr_data(itor)->GetbInPool()) poolSize += ptr_data(itor)->GetSize(); else leakSize += ptr_data(itor)->GetSize(); WPJLOG("MemoryLeak ... %u Bytes\n", ptr_data(itor)->GetSize()); } WPJLOG("MemoryLeak Total is ... %u Bytes\n", leakSize); WPJLOG("MemoryPool Total is ... %u Bytes\n", poolSize); SetLimit(true); }
/***********************************************************************//** * @brief Fetch image pixels * * Fetch the image pixels. This function is in general called if pixel * values should be read or written yet no pixel array is allocated. In case * that pixels existed already before they will be deleted before fetching * new ones. * There are two possibilities to fetch the pixels: * (1) In case that a FITS file is attached to the image, the pixel array * will be loaded from the FITS file using the load_image() method. * (2) In case that no FITS file is attached, a new pixel array will be * allocated that is initalised to zero. ***************************************************************************/ void GFitsImage::fetch_data(void) { // Fetch only if there are pixels in image if (m_num_pixels > 0) { // Allocate and initialise fresh memory alloc_data(); init_data(); // If a FITS file is attached then load pixels from FITS file. if (FPTR(m_fitsfile)->Fptr != NULL) { load_image(type(), ptr_data(), ptr_nulval(), &m_anynul); } } // endif: there were pixels available // Return return; }
void WPJObjectPoolManager::GC(int maxCount = GC_MAX_COUNT) { foreach_in_list_auto(WPJObjectPool*, itor, m_pools) { ptr_data(itor)->GC(maxCount); }
/***********************************************************************//** * @brief Load variable-length column from FITS file * * @exception GException::fits_hdu_not_found * Specified HDU not found in FITS file. * @exception GException::fits_error * An error occured while loading column data from FITS file. * * If a FITS file is attached to the column the data are loaded into memory * from the FITS file. If no FITS file is attached, memory is allocated * to hold the column data and all cells are set to 0. * * The method makes use of the virtual methods * GFitsTableCol::alloc_data, * GFitsTableCol::init_data, * GFitsTableCol::ptr_data, and * GFitsTableCol::ptr_nulval. * These methods are implemented by the derived column classes which * implement a specific storage class (i.e. float, double, short, ...). ***************************************************************************/ void GFitsTableCol::load_column_variable(void) { // If a FITS file is attached then try loading column data from the // FITS file. This may fail in case that no data has yet been written // to the FITS file. In that case we just skip loading and return // the initalised column ... if (FPTR(m_fitsfile)->Fptr != NULL) { // Move to the HDU int status = 0; status = __ffmahd(FPTR(m_fitsfile), (FPTR(m_fitsfile)->HDUposition)+1, NULL, &status); // If this failed because: // - the primary HDU was not found (status 252) // - we moved past the file (status 107) // we assume that no data have yet been written to the file and // we skip the loading. if (status != 252 && status != 107) { // Break on any other cfitsio error if (status != 0) { throw GException::fits_hdu_not_found(G_LOAD_COLUMN_VARIABLE, (FPTR(m_fitsfile)->HDUposition)+1, status); } // Allocate rowstart array m_rowstart.assign(m_length+1, 0); // Determine the column length for each row by looping over // all rows and derive the total memory requirement m_size = 0; m_varlen = 0; m_rowstart[0] = 0; for (int row = 0; row < m_length; ++row) { // Initialise offset and repeat long offset(0); long repeat(0); // Get variable-length of row in repeat status = __ffgdes(FPTR(m_fitsfile), m_colnum, row+1, &repeat, &offset, &status); if (status != 0) { std::string msg = "Unable to get descriptor of row "+ gammalib::str(row+1)+" of column '"+ name()+"' from FITS file."; throw GException::fits_error(G_LOAD_COLUMN_VARIABLE, status, msg); } // Store start of next row m_rowstart[row+1] = m_rowstart[row] + repeat; m_size += repeat; if (repeat > m_varlen) { m_varlen = repeat; } } // endfor: looped over all rows // Allocate and initialise fresh memory alloc_data(); init_data(); // Load data for each row for (int row = 0; row < m_length; ++row) { // Initialise anynul int anynul(0); // Load data status = __ffgcv(FPTR(m_fitsfile), std::abs(m_type), m_colnum, row+1, 1, elements(row), ptr_nulval(), ptr_data(m_rowstart[row]), &anynul, &status); if (status != 0) { std::string msg = "Unable to load row "+gammalib::str(row+1)+"" " of column '"+name()+"' from FITS file."; throw GException::fits_error(G_LOAD_COLUMN_VARIABLE, status, msg); } // Increment anynul m_anynul += anynul; } // endfor: looped over all rows } // endif: no primary HDU found } // endif: there was a FITS file attached // Return return; }