From 37dd051faf2a8085c1abb5623eb5e79363471642 Mon Sep 17 00:00:00 2001 From: Nicola Vigano Date: Thu, 2 Apr 2015 17:07:25 +0200 Subject: astra_mex_direct: Don't initialize newly allocated mxArray This avoids letting matlab initialize the memory we will overwrite shortly after. --- matlab/mex/astra_mex_direct_c.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'matlab/mex') diff --git a/matlab/mex/astra_mex_direct_c.cpp b/matlab/mex/astra_mex_direct_c.cpp index 94eb1cd..38b3f59 100755 --- a/matlab/mex/astra_mex_direct_c.cpp +++ b/matlab/mex/astra_mex_direct_c.cpp @@ -135,7 +135,15 @@ void astra_mex_direct_fp3d(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray* dims[0] = pProjGeom->getDetectorColCount(); dims[1] = pProjGeom->getProjectionCount(); dims[2] = pProjGeom->getDetectorRowCount(); - pOutputMx = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); + + // Allocate uninitialized mxArray of size dims. + // (It will be zeroed by CudaForwardProjectionAlgorithm3D) + const mwSize zero_dims[2] = {0, 0}; + pOutputMx = mxCreateNumericArray(2, zero_dims, mxSINGLE_CLASS, mxREAL); + mxSetDimensions(pOutputMx, dims, 3); + const mwSize num_elems = mxGetNumberOfElements(pOutputMx); + const mwSize elem_size = mxGetElementSize(pOutputMx); + mxSetData(pOutputMx, mxMalloc(elem_size * num_elems)); astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(pOutputMx)); pOutput = new astra::CFloat32ProjectionData3DMemory(pProjGeom, m); @@ -243,7 +251,15 @@ void astra_mex_direct_bp3d(int& nlhs, mxArray* plhs[], int& nrhs, const mxArray* dims[0] = pVolGeom->getGridColCount(); dims[1] = pVolGeom->getGridRowCount(); dims[2] = pVolGeom->getGridSliceCount(); - pOutputMx = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL); + + // Allocate uninitialized mxArray of size dims. + // (It will be zeroed by CudaBackProjectionAlgorithm3D) + const mwSize zero_dims[2] = {0, 0}; + pOutputMx = mxCreateNumericArray(2, zero_dims, mxSINGLE_CLASS, mxREAL); + mxSetDimensions(pOutputMx, dims, 3); + const mwSize num_elems = mxGetNumberOfElements(pOutputMx); + const mwSize elem_size = mxGetElementSize(pOutputMx); + mxSetData(pOutputMx, mxMalloc(elem_size * num_elems)); astra::CFloat32CustomMemory* m = new CFloat32CustomMemory_simple((float *)mxGetData(pOutputMx)); pOutput = new astra::CFloat32VolumeData3DMemory(pVolGeom, m); -- cgit v1.2.3