LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initialize block of memory in CIN

Hello, I am having quite a time trying to initialize a block of memory and then hand a pointer to that memory back to LabVIEW.

1. I pass an uInt8 Array of 3000 elements (6kB) into my LabVIEW CIN
2. I prepare a block of memory in the CIN.
3. I initialize the memory by loading a static table into the block of memory
4. I WANT to move the initialized memory space into the uInt8 Array, starting at index[0]

The code below compiles, but when I run the CIN in labview, LV crashes.  

What am I doing wrong?

Thank you for any help,
Victor

/* Typedefs */

typedef struct {
    int32 dimSize;
    uInt8 globalData2[1];
    } TD1;
typedef TD1 **TD1Hdl;

typedef struct _LANGUAGE_ENTRY
  {
        UCHAR           Language;
        PVOID             pTable;
    } LANGUAGE_ENTRY;

extern LTABLE LANGUAGE_TABLE

void *memPtr;

extern "C"{
MgErr CINRun(TD1Hdl globalData);
}

MgErr CINRun(TD1Hdl globalData)
    {
    uInt16 usSize;
    LANGUAGE_ENTRY MyLanguages[2];

    usSize = 5576; //GlobalDataSize

    memPtr = malloc( usSize );

    memset( memPtr, 0, sizeof(memPtr) );

    MyLanguages[0].Language = ENGLISH;
    MyLanguages[0].pTable = (void*)LTABLE LANGUAGE_TABLE;
    MyLanguages[1].Language = 0;
    MyLanguages[1].pTable = 0;

    Initialize ( MyLanguages, memPtr);
    
    MoveBlock(memPtr, (*globalData)->globalData2, usSize);

    return noErr;
    }
0 Kudos
Message 1 of 2
(2,331 Views)
Hi Victor,
I think the reason LabVIEW is crashing is because it isn't happy with the pointer you are giving it or the way you are giving it. I personally am not that familiar with C code, but my suggestion would be to use the malloc function. The LabVIEW help on the Memory Manager (Fundamentals » Calling Code Written in Text-Based Programming Languages » Concepts » CINs » LabVIEW Manager Routines) is a great place to start. It describes the functions to use to pass pointers as parameters and links to the Memory Manager page which talks about Using Pointers for Dynamic Memory Allocation. You could also create the array and specify the memory to use for it rather than the other way around and then move the array there. I hope this helps!
 
Stephanie
0 Kudos
Message 2 of 2
(2,307 Views)