LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Fatal internal error:"memory.cpp",line 593"

I need some help.

Can some please explain what i am doing wrong here. i have created a Dll from a LV 7.0 vi. The header file looks something like this:

typedef struct {
long dimSize;
double elt[1];
} TD2;
typedef TD2 **TD2Hdl;

typedef struct {
double f0;
double df;
TD2Hdl magnitude;
} TD1;

void __cdecl Spectrum(double freq, double amp, TD1 *Spec);

And i have the following code where i allocate memory and attempt to call 'Spectrum':-

TD1 *Power;
double frequency=10, amplitude=1;
Power = (TD1 *) malloc(sizeof(TD1));
(*Power).magnitude = (TD2**)malloc(sizeof(TD2));
*(*Power).magnitude = (TD2*)malloc(5000*sizeof(TD2));

(*Power->magnitude)->dimSize = 5000;

for (i=0; i<500;
i++) {
(*Power->magnitude)->elt[i] = 0;
}

Spectrum(frequency, amplitude, Power);

I keep getting Fatal internal error: "memory.cpp", line 593" when it tries to call Spectrum. I believe i have allocated memory correctly although i may be wrong. (I was getting 'exception' errors before). The VI i used to create the Dll contains a basic 'Function Generator' (sine wave) and a 'Power Spectrum'.
I have looked at the Knowledge base and dll examples that come with LV 7.0 and have tried setCINArray and NumericArrayResize but have not had any luck. It seems like the documentation is for LV 6.0 and 6.1.

Has anybody seen this or have any idea why i am getting this?

Thanks
0 Kudos
Message 1 of 7
(3,597 Views)
Hello wewe,

At first glance it looks like your memory error may have something to do with your for loop that it initializing elt[i] = 0. When you define that struct, you set elt as a single element array. In the for loop, you are trying to access 500 elements of that array. You are indexing out of that array and probably setting all the memory after it to 0.

Hope this helps. If not, let me know, and I�d be happy to look further into it.

Have a nice day!

Robert M
Applications Engineer
National Instruments
Robert Mortensen
Software Engineer
National Instruments
0 Kudos
Message 2 of 7
(3,597 Views)
> Can some please explain what i am doing wrong here. i have created a
> Dll from a LV 7.0 vi. The header file looks something like this:
>


> double frequency=10, amplitude=1;
> Power = (TD1 *) malloc(sizeof(TD1));
> (*Power).magnitude = (TD2**)malloc(sizeof(TD2));
> *(*Power).magnitude = (TD2*)malloc(5000*sizeof(TD2));
>
> (*Power->magnitude)->dimSize = 5000;
>
> for (i=0; i<500; i++) {
> (*Power->magnitude)->elt[i] = 0;
> }
>
> Spectrum(frequency, amplitude, Power);
>
> I keep getting Fatal internal error: "memory.cpp", line 593" when it
> tries to call Spectrum. I believe i have allocated memory correctly
> although i may be wrong. (I was getting 'exception' errors before).
> The VI i used to create the Dll contains a basic
'Function Generator'
> (sine wave) and a 'Power Spectrum'.
> I have looked at the Knowledge base and dll examples that come with LV
> 7.0 and have tried setCINArray and NumericArrayResize but have not had
> any luck. It seems like the documentation is for LV 6.0 and 6.1.
>

It looks to me like you are constructing arrays to pass to LV using
malloc, instead of the labview.lib functions for creating or resizing LV
array handles.

You should refer to the manual on Calling External code for details on
the construction of an array.

Greg McKaskle
0 Kudos
Message 3 of 7
(3,597 Views)
Thanks for the reply. I have used malloc before successfully. I tried using 'NumericArrayResize' but it seems to want a pointer to a handle of 'unsigned char' but my data is a numeric array. For intance if i have the following:-

typedef struct {
long dimSize;
double elt[1];
} TD3;
typedef TD3 **TD3Hdl;

TD3Hdl *Tach

noErr = NumericArrayResize(fD, 1, Tach, 80000);

...

It does not compile i get the following error:-

error C2664: 'NumericArrayResize' : cannot convert parameter 3 from 'TD3 *** ' to 'unsigned char *** '

Don't know what i am doing wrong here?
0 Kudos
Message 4 of 7
(3,597 Views)
> typedef struct {
> long dimSize;
> double elt[1];
> } TD3;
> typedef TD3 **TD3Hdl;
>
> TD3Hdl *Tach
>
> noErr = NumericArrayResize(fD, 1, Tach, 80000);
>
> ..
>
> It does not compile i get the following error:-
>
> error C2664: 'NumericArrayResize' : cannot convert parameter 3 from
> 'TD3 *** ' to 'unsigned char *** '
>

Just as with malloc, it isn't odd to need to cast to get from the
allocation to the pointer where it is stored.

You do want to use NumericArrayResize or DSNewHandle/DSSetHandleSize
functions. The DS functions take void and don't typically need casting,
but the NumericResize apparently does.

I don't have the documentation in front of me, but if you make a local
with value of zero/null, and pass the addres
s of the local into
NumericArrayResize, it should work fine. Make sure to either assign the
handle into something given to LV or to dispose of it yourself.

Greg McKaskle
0 Kudos
Message 5 of 7
(3,597 Views)
typedef struct {
long dimSizes[2];
double Numeric[1];
} TD8;
typedef TD8 **TD8Hdl;

TD8Hdl *spec_map;

DSSetHandleSize(*spec_map, sizeof(int32)*2 + 100*10*sizeof(double) );

Greg could you please explain what is wrong with this because i am still getting an "exception" error.
0 Kudos
Message 6 of 7
(3,596 Views)
> typedef struct {
> long dimSizes[2];
> double Numeric[1];
> } TD8;
> typedef TD8 **TD8Hdl;
>
> TD8Hdl *spec_map;
>
> DSSetHandleSize(*spec_map, sizeof(int32)*2 + 100*10*sizeof(double) );
>
> Greg could you please explain what is wrong with this because i am
> still getting an "exception" error.

You are only giving a small snippet of code, but it looks like you have
a variable, spec_map with an uninitialized value. When calling
DSSetHandleSize, you are dereferencing this variable and you are
probably crashing right there, before you even make the function call.
And if you get lucky and the value is able to be dereferenced, the DSSet
function will be asked to resize a nonexistant handle and will hopefully
ret
urn an error that the argument is invalid.

To allocate a handle, you use DSNewHandle which is used as *spec_map=
DSNewHandle(size);

Normally you would be given a param where the handle is already
allocated and just needs to be resized. In that case, use the
SetHandleSize.

Greg McKaskle
0 Kudos
Message 7 of 7
(3,596 Views)