int main(int argc, char *argv[]){ #ifdef MEMORY_PERCENTAGE printf("Currently total memory: %zd\n",getTotalSystemMemory()); printf("Currently avail memory: %zd\n",getFreeSystemMemory()); #endif int i; for(i=0;i<argc;i++){ char *arg=argv[i]; if(strcmp(arg, "-h")==0 || strcmp(arg,"-?")==0 || argc==1){ printf("Usage: eatmemory <size>\n"); printf("Size can be specified in megabytes or gigabytes in the following way:\n"); printf("# # Bytes example: 1024\n"); printf("#M # Megabytes example: 15M\n"); printf("#G # Gigabytes example: 2G\n"); #ifdef MEMORY_PERCENTAGE printf("#%% # Percent example: 50%%\n"); #endif printf("\n"); }else if(i>0){ int len=strlen(arg); char unit=arg[len - 1]; long size=-1; int chunk=1024; if(!isdigit(unit) ){ if(unit=='M' || unit=='G'){ arg[len-1]=0; size=atol(arg) * (unit=='M'?1024*1024:1024*1024*1024); } #ifdef MEMORY_PERCENTAGE else if (unit=='%') { size = (atol(arg) * (long)getFreeSystemMemory())/100; } #endif else{ printf("Invalid size format\n"); exit(0); } }else{ size=atoi(arg); } printf("Eating %ld bytes in chunks of %d...\n",size,chunk); if(eat(size,chunk)){ printf("Done, press any key to free the memory\n"); getchar(); }else{ printf("ERROR: Could not allocate the memory"); } } } }
int main(int argc, char **argv) { // announce musichq printf("Simplified Audio\n"); printf("musichq: Ver %s / Build %s / Date %s\n", getProgVer().toAscii().constData(), getBuildVer().toAscii().constData(), getBuildDate().toAscii().constData()); printf("\n"); printf("OS memory free: %d Mb\n", (int) getFreeSystemMemory()); printf("Libraries: "); #if defined(USE_MP4) printf("MP4, "); #endif #if defined(USE_MEDIA_PHONON) printf("phonon, "); #elif defined(USE_MEDIA_GSTREAMER) printf("gstreamer, "); #elif defined(USE_MEDIA_ZERO) printf("zero media, "); #endif printf("\n"); printf("\n"); fflush(stdout); // Install own msg handler.. want 100% control! qInstallMsgHandler(myMessageOutput); // Initialize Application... QCoreApplication app(argc, argv); app.setApplicationName("musichq"); // .. and then ready! int err = args(app.argc(), app.argv()); if (err) return err; // create media backend MediaInterface *media; #if USE_MEDIA_PHONON media = new MediaPhonon(); #elif USE_MEDIA_GSTREAMER media = new MediaGStreamer(); #elif USE_MEDIA_ZERO media = new MediaZero(); #endif theSoup = new TheSoup(mySettings.cache_search); stats = new Stats(); mediaPlayer = new MediaPlayer(media); lastfm = new ServiceLastFM(mySettings.lastfm_apikey); mount = new Mount(); scan = new Scan(); // _after_ mount! alive = new Alive(); httpServer = new HttpServer(); httpServer->addHeader(new HttpHdrStatus()); httpServer->addListener(new HttpGetSearch()); httpServer->addListener(new HttpGetCover()); httpServer->addListener(new HttpGetThumb()); httpServer->addListener(new HttpGetPlayer()); httpServer->addListener(new HttpGetMixtape()); httpServer->addListener(new HttpGetStatus()); httpServer->addListener(new HttpGetSystem()); httpServer->addListener(new HttpGetManifest()); httpServer->addListener(new HttpGetAudio()); httpServer->addListener(new HttpGetAll()); /* _must_ be last! */ lastfm->start(); scan->start(); mount->start(); if (httpServer->start(mySettings.http_port)) { alive->start(); app.exec(); alive->stop(); httpServer->stop(); } mount->stop(); scan->stop(); lastfm->stop(); worker.wait(); delete httpServer; delete alive; delete mount; delete scan; delete lastfm; delete mediaPlayer; delete theSoup; delete stats; return worker.exitCode(); }