Pass a structure with an element being a vector

I have a class that creates a dll implemented as a single solution. In its header file, I have a structure with an element being a vector. eg:

// dll.h struct ScanParam16 { // int param int nChanDetX, nChanDetZ; int nViewPerRot, nViewPerSlice, nChanDetXPerMod; int nImgXY, nImgZ; int nSlicePerProcess, n2Group; int FFTLen; // float param float pitch; float isoOffX, isoOffZ; float fov, dfov; float imgCentX, imgCentY, imgCentZ; float sdd, srad, drad; float dDetX, dDetZ, dDetU, dDetV, interModGapX, dDetSampleRes; std::vector<float> winArray; bool interleave; // enum bpInterpType16 iType; }; 

In the code that calls this DLL, the winArrar vector is evaluated as follows:

 // caller.cpp static ScanParam16 param; param.FFTLen = 2048; float* wArray = new float[param.FFTLen]; GenKernCoef(wArray, param.FFTLen, kType, ParaDataFloat, aram.dDetSampleRes); std::vector<float> v(wArray, wArray+param.FFTLen); param.winArray = v; 

Now everything looks good. I see that param.winArray is set correctly with the correct values.

However, when I pass param as a parameter, param.winArray becomes 0 in quality / length, as I observe inside the dll.

Here's how the parameter is passed:

 //caller.cpp ReconAxial16 operator; operator.Init( param ) ; 

Above is the point located immediately before passing the parameter to the dll.

And below is the point at which the parameter falls inside the dll:

 // dll.cpp void ReconAxial16::Init(const ScanParam16& param ) { /**************************************************************/ // setup geometry and detv /**************************************************************/ SetupGeometry(param); // Allocate buffer for reconstructed image (on cpu side) _img = (float *)malloc(_nImgXY * _nImgXY * sizeof(float)); ...... } 

Here, when I enter, I see that param.winArray has a length of 0, but all other parameters look fine.

I can’t stand it and am wondering how to correctly convey the vector? Thank you very much.

+5
source share
1 answer

In fact, I have no answer to these questions, but I just imagine how I did what I wanted, bypassing it.

I basically extract an array / vector from the structure and pass it separately as a second argument, something like this:

  //caller.cpp ReconAxial16 operator; float* wArray = new float[param.FFTLen]; GenKernCoef(wArray, param.FFTLen, kType, ParaDataFloat, param.dDetSampleRes); operator.Init( param, wArray ) ; 

Of course, in the dll project, I did something like this so that it takes an array as an extra argument:

 // dll.h LONG SetupGeometry( const ScanParam16 &param, float* wArray); 

It worked. I walked in and saw that wArray correctly passed to the dll.

0
source

All Articles