comparison data/fft/FFTDataServer.cpp @ 205:05154c7bb90b

* Basics of an approximate way of managing memory that we've committed to using but haven't allocated yet
author Chris Cannam
date Fri, 15 Dec 2006 18:05:31 +0000
parents 11e107062a2b
children e0e7f6c5fda9
comparison
equal deleted inserted replaced
204:29b70bdaacdc 205:05154c7bb90b
391 391
392 #ifdef DEBUG_FFT_SERVER 392 #ifdef DEBUG_FFT_SERVER
393 std::cerr << "Width " << m_width << ", cache width " << m_cacheWidth << " (size " << m_cacheWidth * columnSize << ")" << std::endl; 393 std::cerr << "Width " << m_width << ", cache width " << m_cacheWidth << " (size " << m_cacheWidth * columnSize << ")" << std::endl;
394 #endif 394 #endif
395 395
396 StorageAdviser::notifyPlannedAllocation
397 (m_memoryCache ? StorageAdviser::MemoryAllocation :
398 StorageAdviser::DiscAllocation,
399 m_compactCache ? minimumSize : maximumSize);
400
396 for (size_t i = 0; i <= m_width / m_cacheWidth; ++i) { 401 for (size_t i = 0; i <= m_width / m_cacheWidth; ++i) {
397 m_caches.push_back(0); 402 m_caches.push_back(0);
398 } 403 }
399 404
400 m_fftInput = (fftsample *) 405 m_fftInput = (fftsample *)
434 } 439 }
435 440
436 QMutexLocker locker(&m_writeMutex); 441 QMutexLocker locker(&m_writeMutex);
437 442
438 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) { 443 for (CacheVector::iterator i = m_caches.begin(); i != m_caches.end(); ++i) {
439 delete *i; 444 if (*i) {
445 delete *i;
446 } else {
447 StorageAdviser::notifyDoneAllocation
448 (m_memoryCache ? StorageAdviser::MemoryAllocation :
449 StorageAdviser::DiscAllocation,
450 m_cacheWidth * m_height *
451 (m_compactCache ? sizeof(uint16_t) : sizeof(float)) / 1024 + 1);
452 }
440 } 453 }
441 454
442 deleteProcessingData(); 455 deleteProcessingData();
443 } 456 }
444 457
581 } 594 }
582 595
583 cache->resize(width, m_height); 596 cache->resize(width, m_height);
584 cache->reset(); 597 cache->reset();
585 598
599 StorageAdviser::notifyDoneAllocation
600 (m_memoryCache ? StorageAdviser::MemoryAllocation :
601 StorageAdviser::DiscAllocation,
602 width * m_height *
603 (m_compactCache ? sizeof(uint16_t) : sizeof(float)) / 1024 + 1);
604
586 } catch (std::bad_alloc) { 605 } catch (std::bad_alloc) {
587 std::cerr << "ERROR: Memory allocation failed in FFTFileCache::resize:" 606 std::cerr << "ERROR: Memory allocation failed in FFTFileCache::resize:"
588 << " abandoning this cache" << std::endl; 607 << " abandoning this cache" << std::endl;
589 //!!! Shouldn't be using QtGui here. Need a better way to report this. 608 //!!! Shouldn't be using QtGui here. Need a better way to report this.
590 QMessageBox::critical 609 QMessageBox::critical