diff options
author | Nicola Vigano <nicola.vigano@esrf.fr> | 2015-04-02 17:07:25 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-10-09 11:47:10 +0200 |
commit | 37dd051faf2a8085c1abb5623eb5e79363471642 (patch) | |
tree | 3c1b09f55f9f1555d292c8538866a79f3de625f6 /matlab/mex | |
parent | 793afbc3fa1cca64292716869e503cb66942606d (diff) | |
download | astra-37dd051faf2a8085c1abb5623eb5e79363471642.tar.gz astra-37dd051faf2a8085c1abb5623eb5e79363471642.tar.bz2 astra-37dd051faf2a8085c1abb5623eb5e79363471642.tar.xz astra-37dd051faf2a8085c1abb5623eb5e79363471642.zip |
astra_mex_direct: Don't initialize newly allocated mxArray
This avoids letting matlab initialize the memory we will overwrite shortly
after.
Diffstat (limited to 'matlab/mex')
-rwxr-xr-x | matlab/mex/astra_mex_direct_c.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
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); |