从InputStream中避免Netty副本

时间:2016-05-03 22:48:27

标签: netty

Betty有一个很棒的灵活抽象层,用于表示可以与NIO一起运行的读写缓冲区。在Netty 4中,这是ByteBuf类,在Netty 3中,这是ChannelBuffer。

我正在处理一个库(JDBC),它为一段数据返回一个InputStream,作为内部存储引擎的一部分。当前代码将此副本复制到中间字节数组,并在将此字节数组提供给Netty进行处理之前构建ChannelBuffer。我正在尝试减少在此堆栈中发生的不必要的副本的数量,并且希望将InputStream直接传递给Netty而不使用中间副本,以便Netty可以将InputStream的内容直接写入套接字而无需分配任何大型中间对象。 Netty中是否有任何工具允许从不调用数据集完整副本的InputStream创建只读ChannelBuffer / ByteBuf?

1 个答案:

答案 0 :(得分:1)

您所寻找的可能是 //--------------Compute for calibration------------------- N = n_boards*n; objectPoints.resize(N); for( i = 0; i < ny; i++ ) for(j = 0; j < nx; j++ ) objectPoints[i*nx + j] = cvPoint3D32f(i*squareSize, j*squareSize, 0); for( i = 1; i < n_boards; i++ ) copy( objectPoints.begin(), objectPoints.begin() + n, objectPoints.begin() + i*n ); npoints.resize(n_boards,n); CvMat _objectPoints = cvMat(1, N, CV_32FC3, &objectPoints[0] ); CvMat _imagePoints1 = cvMat(1, N, CV_32FC2, &points[0][0] ); CvMat _imagePoints2 = cvMat(1, N, CV_32FC2, &points[1][0] ); CvMat _npoints = cvMat(1, npoints.size(), CV_32S, &npoints[0] ); cvSetIdentity(&_M1calib); cvSetIdentity(&_M2calib); cvZero(&_D1); cvZero(&_D2); printf("\nRunning stereo calibration ..."); fflush(stdout); cvStereoCalibrate( &_objectPoints, &_imagePoints1, &_imagePoints2, &_npoints,&_M1calib, &_D1, &_M2calib, &_D2,imageSize, &_R, &_Tcalib, &_E, &_F, cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 100, 1e-5), CV_CALIB_FIX_ASPECT_RATIO+CV_CALIB_ZERO_TANGENT_DIST + CV_CALIB_SAME_FOCAL_LENGTH ); printf("\nDone Calibration"); cvUndistortPoints( &_imagePoints1, &_imagePoints1,&_M1calib, &_D1, 0, &_M1calib ); cvUndistortPoints( &_imagePoints2, &_imagePoints2,&_M2calib, &_D2, 0, &_M2calib ); CvMat* mx1calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F ); CvMat* my1calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F ); CvMat* mx2calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F ); CvMat* my2calib = cvCreateMat( imageSize.height,imageSize.width, CV_32F ); double R1[3][3], R2[3][3], P1[3][4], P2[3][4]; CvMat _R1 = cvMat(3, 3, CV_64F, R1); CvMat _R2 = cvMat(3, 3, CV_64F, R2); CvMat _P1 = cvMat(3, 4, CV_64F, P1); CvMat _P2 = cvMat(3, 4, CV_64F, P2); cvStereoRectify( &_M1calib, &_M2calib, &_D1, &_D2, imageSize,&_R, &_Tcalib,&_R1, &_R2, &_P1, &_P2, &_Qcalib,0/*CV_CALIB_ZERO_DISPARITY*/ ); cvInitUndistortRectifyMap(&_M1calib,&_D1,&_R1,&_P1,mx1calib,my1calib); cvInitUndistortRectifyMap(&_M2calib,&_D2,&_R2,&_P2,mx2calib,my2calib); ChunkedWriteHandler