**I am facing the following problem:**  

I use a C++ program to control a scientific camera that is connected to my PC. It takes photos with short shutter times as fast as possible (ca. 1sec per image). 

At its current stage, the program saves each photo to the hard drive immediately after it has been made. It appears, that the `I/O` access takes a lot of time (ca. 1/2 s per saving) which drastically lowers the image rate. 

I've been thinking about storing many images first (say, in an array) and then save them all in one batch.  

Would that work? Are there any good alternatives? How would one handle such a problem?

Making a video instead of an image is not an option.

Thank you very much

EDIT: Here is the code I am using:

```
    // capture loop: add up 'preint' images read out with 12 bit adc resolution
    // and save them as 16 bit image

    // read out current shutter register
    // read the 32-bit hex value into the unsigned long member of the above defined union
    cam.ReadRegister( 0x918, &curShutter.ulValue );
    fCurShutter = curShutter.fValue;

    cout << "Grab # " << ip.cnt << "; Serv: " << ip.servopos << "; Expt: " << ip.exptime << "; T: " << ip.temp  << "; prog " ;

    //inner capture loop
    for ( int imageCnt=0; imageCnt < ip.preint; imageCnt++ )
    {
        error = cam.RetrieveBuffer( &monoImage );
        if (error != PGRERROR_OK){PrintError( error ); continue;}

        cout << "." ;

        //convert to cv::Mat image
        unsigned int rowBytes = (double)monoImage.GetReceivedDataSize()/(double)monoImage.GetRows();
        cv_image = cv::Mat(monoImage.GetRows(), monoImage.GetCols(), CV_16UC1, monoImage.GetData(),rowBytes);

        cv_sum_image = cv_sum_image + cv_image/ip.preint;

        cv::imshow("image", cv_sum_image);
        cv::waitKey(1);
    }

    //t=GetTickCount() - t;
    unsigned int shutterus = fCurShutter*1000000;

    {
    //create filename and save co-added image
    ostringstream filename;
    filename << ip.mode <<"_"<< ip.cdt << "_"   << setfill('0') << setw(5) << ip.cnt << "_" << ip.servopos << "_" << setfill('0') << setw(6) << shutterus << "_" << ip.preint << "_" << ip.temp << "_" << ip.pres <<".pgm";
    //cv::string ss = filename.str();
    string ss = filename.str();
    cv::imwrite(ss,cv_sum_image);
    }

    // Stop capturing images
    error = cam.StopCapture();
    if (error != PGRERROR_OK){PrintError( error ); return -1;}

    // Disconnect the camera
    error = cam.Disconnect();
    if (error != PGRERROR_OK){ PrintError( error ); return -1;}

    return 0;
}

```

Maybe the issue lies within the opencv routine?