LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

FATAL RUN-TIME ERROR: Dynamic memory is corrupt.

hello,

I have a Write() - function which agrees array handed over which writes to me different worth in a file. if I liked to call now this function with a button the following error comes:

 

FATAL RUN-TIME ERROR:   Dynamic memory is corrupt.


if I call the function in the main (), NO error comes.
can somebody say to me what I have made wrong?

Thanks

 


int CVICALLBACK GenerateFileCallback (int panel, int control, int event,  void *callbackData, int eventData1, int eventData2)
{
     STRUCT_STEP_VALUES ARRGenerate;
 
    switch (event)
    {
                  case EVENT_COMMIT:
                               ARRGenerate = WriteFile( arrayWriteFile ); 
                               WriteOutputFile( &ARRGenerate );
                               break;
     }
     return 0;
}

0 Kudos
Message 1 of 3
(3,583 Views)

I'll take a crack at this ...

 

I think by "worth" you may mean "values",  and "agrees"  means "accepts", "handed over" means "passed in".   Looks like auto-translation maybe Smiley Wink

 

If ARRGenerate is the returned array address (i.e.. array name) from your function WriteFile, then when you reference it with the address operator & you''re getting the address of the address of the array, not the address of the array.

 

So when you call WriteOutputFile (&ARRGenerate) you could get a memory violation.

 

Maybe it should be this:

 

WriteOutputFile (ARRGenerate);

 

In C, the name of the array is actually a pointer to the first element of the array.  So to get the address of the array, you just use its name, you don't need to reference it again with the & operator.

 

Menchar

Message Edited by menchar on 04-06-2009 08:08 PM
0 Kudos
Message 2 of 3
(3,516 Views)

My bad -

 

&arrayname evaluates the same as arrayname in C ... so ignore previous post ...

 

Where is arrayWriteFile defined?    Is it WriteFile ( )   or   WriteOutputFile ( ) that gives the error?


Menchar

 

0 Kudos
Message 3 of 3
(3,512 Views)