int main() { Mem mem; cout << mem.moved() << endl; mem.pointer(1); cout << mem.moved() << endl; MyString s("My test string"); s.print(cout); s.concat(" some additional stuff"); s.print(cout); MyString s2; s2.concat("Using default constructor"); s2.print(cout); } ///:~
/** called once a minute from killcursors thread */ void sayMemoryStatus() { static time_t last; static Mem mlast; try { ProcessInfo p; if ( !cmdLine.quiet && p.supported() ) { Mem m; m.res = p.getResidentSize(); m.virt = p.getVirtualMemorySize(); m.mapped = MemoryMappedFile::totalMappedLength() / (1024 * 1024); time_t now = time(0); if( now - last >= 300 || m.grew(mlast) ) { log() << "mem (MB) res:" << m.res << " virt:" << m.virt; long long totalMapped = m.mapped; if (cmdLine.dur) { totalMapped *= 2; log() << " mapped (incl journal view):" << totalMapped; } else { log() << " mapped:" << totalMapped; } log() << " connections:" << connTicketHolder.used(); if (theReplSet) { log() << " replication threads:" << ReplSetImpl::replWriterThreadCount + ReplSetImpl::replPrefetcherThreadCount; } last = now; mlast = m; } } } catch(const std::exception&) { log() << "ProcessInfo exception" << endl; } }
/** called once a minute from killcursors thread */ void sayMemoryStatus() { static time_t last; static Mem mlast; try { ProcessInfo p; if ( !cmdLine.quiet && p.supported() ) { Mem m; m.res = p.getResidentSize(); m.virt = p.getVirtualMemorySize(); m.mapped = (int) (MemoryMappedFile::totalMappedLength() / ( 1024 * 1024 )); if( time(0)-last >= 300 || m.grew(mlast) ) { log() << "mem (MB) res:" << m.res << " virt:" << m.virt << " mapped:" << m.mapped << endl; if( m.virt - (cmdLine.dur?2:1)*m.mapped > 5000 ) { ONCE log() << "warning virtual/mapped memory differential is large. journaling:" << cmdLine.dur << endl; } last = time(0); mlast = m; } } } catch(...) { log() << "ProcessInfo exception" << endl; } }
void MyString::print(ostream& os) { if (!buf) return; os << buf->pointer() << endl; }
void MyString::concat(char *str) { if (!buf) buf = new Mem; strcat((char *) buf->pointer(buf->msize() + strlen(str) + 1), str); }
/* * Read the message from the rtdServer and call a virtual method to * display the image and evaluate the tcl event scripts. */ int RtdCamera::fileEvent() { Mem mem; rtdIMAGE_INFO info; int stat; memset(&info, '\0', sizeof(rtdIMAGE_INFO)); info.semId = info.shmNum = -1; stat = rtdRecvImageInfo(eventHndl_, &info, verbose_, buffer_); semId_ = info.semId; shmNum_ = info.shmNum; if (stat != RTD_OK || checkType(info.dataType) != RTD_OK || info.xPixels <=0 || info.yPixels <= 0) { checkStat(); return TCL_ERROR; } if ( ! attached()) { semDecr(); return TCL_OK; } /* * class Mem takes care of possible reusing previous shared memory areas * and cleanup. Choose the constructor depending on whether the * semaphore fields of the image info have been set. */ int bytes = info.xPixels * info.yPixels * (abs(info.dataType) / 8); if (semId_ > 0) mem = Mem(bytes, info.shmId, 0, verbose_, shmNum_, semId_); else mem = Mem(bytes, info.shmId, 0, verbose_); if (mem.status() != 0) { checkStat(); return TCL_ERROR; } dbl_->log("image event: Id=%d, x=%d, y=%d, width=%d, height=%d, " "shmId=%d shmNum=%d semId=%d\n", info.frameId, info.frameX, info.frameY, info.xPixels, info.yPixels, info.shmId, shmNum_, semId_); /* * before displaying the image delete the file handler. This blocks * new image events which must not be handled between camera pre/post commands. */ fileHandler(0); // call the virtual method in a derived class to display the image int disperr = display(info, mem); // re-install the file handler fileHandler(1); // finally decrement the semaphore semDecr(); return disperr; }