NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Use TestStand Create *ptr & transfer this pointer into DLL (malloc memory)

Excuse me
 
My target is
to create a pointer at TestStand , then transfer this pointer into DLL that be built by Visual C++ , then dynamic memory allocation with C code
 
My action is:
I create a 'Custom Data Type' for "Pointer" type
 
Then
in StationGlobals of variable area , create a variable(name : ptr) that is "Pointer" type
 
I want to transfer ptr into DLL , setting as image : http://img301.imageshack.us/img301/6608/transfersettingqy8.jpg
 
 
DLL (source code)
=====================================================
#include<stdio.h>
#include<stdlib.h>
__declspec(dllexport) void Test_Empty_Array_into_DLL(double *array)
{
   FILE *ptr=fopen("create_memory.txt","w+");
   array=(double*)malloc(sizeof(double)*50);
   int count;
   for(count=0;count<50;count++)
   {
    array[count]=count*2;
    fprintf(ptr,"%f\n",array[count]);
   }
   fclose(ptr);
}
====================================================
 
 
Yes, this result is OK(write some test's number into *.txt )
 
But , I don't know how to use those memory space that already be created on VisualC++ on teststand
 
I hope to use those space (array[50]) at TestStand
 
 
BTW. On TestStand platform , how to operate 'dynamic memory allocation '??
 
 
Pls give me some suggestion , thanks
best regards!


由 stockton 在 07-11-2008 02:51 AM 上編輯的訊息
0 Kudos
Message 1 of 4
(3,764 Views)
Hello stockton,
 
Allocating the memory in TestStand (as opposed to inside of the DLL) is the best thing to do.  This ensures that the memory will be allocated within TestStand and then later     deallocated by TestStand.  Otherwise, if the memory was allocated inside of the DLL and then passed back to TestStand for use, what would happen if memory were later deallocated within the DLL but TestStand was still using it?  This would cause major headache. Doing the allocation from within the TestStand environment is by far the best choice.
 
For labview application using DLL, it holds the same situation. You may reference to the following link
 
I hope this helps
 
 
Alexander, NI Taiwan Engineer
0 Kudos
Message 2 of 4
(3,700 Views)

Thanks for Alexandre's help

If I don't sure array size that be used during coding program

This size must be calculated during program execution

What can I do?

Create enough memory size for maximum. Is good way?   @_@

 

and how to execute dymanic memory allocation on TestStand??

thanks!!

 

 

0 Kudos
Message 3 of 4
(3,695 Views)
Hello stockton,
 
    To dynamically allocate memory for array, you may reference to the following examples:
    C:\Program Files\National Instruments\TestStand 4.0\Examples\AccessingArraysUsingAPI
    As you can see from TestStand_001.jpg, originally there are only three arrays.
    During the process of execution, we use teststand API to create 2D array (TestStand_002.jpg).
 
    Please let me know if you have any other problems.
 
   Alexander, NI Taiwan Engineer
Download All
0 Kudos
Message 4 of 4
(3,686 Views)