LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: How do I get the memory address of an array?

Solved!
Go to solution

Hi,

I have a 1D Array which is having a hex data in it. I have int pointer as a structure element which should get the memory address of array. (Pointer points to my 1D array in c code).

 

How can I implement that in labVIEW?

  

0 Kudos
Message 1 of 18
(3,855 Views)

So you need a 1D array and an index to be able to index elements using IndexArray???


Why don't you show your C code and your current state of the VI?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 18
(3,851 Views)

Your language is not very clear. Is your pointer stored in an int variable inside the structure (which would be BAAAD and non 64 bit compatible) or is it a pointer to an int? I can only echo Gerd's remark: Show your codes!

It is beyond me how people expect to get useful help in programming problems from two lines of vaguely formulated prosa about their problem. To my knowledge, nobody on this forum has magic mind reading capabilities to correctly guess what your problem might be.

 

And yes when posting VI code, please do a save for previous and save it for at least 2 versions earlier than the current version since not everyone has the luxury to install the latest and greatest version of LabVIEW on his work machine. You do want to increase the chance for people to be able to look at your code, as it benefits you! I and many others on this fora do this voluntarily and have their regular work to do besides this, so I simply stopped to bother about most posts that make me jump through hoops in order to even try to help.

Rolf Kalbermatter
My Blog
Message 3 of 18
(3,834 Views)

I'm assuming you're talking about

struct {

  something

  something

  int* Array[]

}

 

In LabVIEW it'd be a cluster with [Something, Something, Int Array].

Whenever you use the Array wire, it uses a pointer internally, you just can't/shouldn't use/access it.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 18
(3,802 Views)

And I would add to that: Clean up your VIs before you post them.

When someone asks for help and posts a VI with a messy block diagram, I generally ignore it.

 

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 18
(3,785 Views)

SNP@25 wrote:

Hi,

I have a 1D Array which is having a hex data in it. I have int pointer as a structure element which should get the memory address of array. (Pointer points to my 1D array in c code).

 

How can I implement that in labVIEW?

  


I don't understand why you would need to know the memory location. Why does it even matter where the array is stored in memory? 

 

LabVIEW abstract the need for such low level access like memory locations and pointers.

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 18
(3,771 Views)

@paul_cardinale wrote:

And I would add to that: Clean up your VIs before you post them.

When someone asks for help and posts a VI with a messy block diagram, I generally ignore it.

 


A messy block diagram is like text code with random indents.  The compiler won't care, but I'd look the other way if the next developer to take over your code went and strangled you.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 7 of 18
(3,748 Views)

Hi,

Thank you for your kind gesture GerdW.

 

Code is as below:

 

typedef struct

{

void * ExtraDataPtr;

} msg;

 

unsigned char iDataBytes[]={0,1,2,3,4,5,6,7,8,9,10};

msg.ExtraDataPtr = &iDataBytes;

 

I have defined this 'msg' structure in labVIEW using 'Cluster'. I have iDataBytes 1-D array also created in my VI.

Now I am willing to implement  msg.ExtraDataPtr = &iDataBytes this in LabVIEW.

 

 

Regards,

S.

 

0 Kudos
Message 8 of 18
(3,731 Views)

Hi SNP,

 

and what do you want to achieve in LabVIEW with this C code?

 

It seems to me you only need an array containing the numbers from 0 to 10…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 18
(3,727 Views)

If the code is as below this will definitely not work!

 

typedef struct
{
    void * ExtraDataPtr;
} MessageRecord;

int MyFunnyFunc(MessageRecord *msg)
{
    unsigned char iDataBytes[]={0,1,2,3,4,5,6,7,8,9,10};
    msg->ExtraDataPtr = &iDataBytes;
}

iDataBytes is allocated on the stack when entering the function and the stack is cleaned up when leaving the function making the memory iDataBytes uses undefined at the time your function returns to LabVIEW.

 

If iDataBytes is instead a global static variable outside any function then this would not be the case but it is pretty cumbersome and problematic to return pointers like this to any caller, not just LabVIEW alone.

 

Better would be to do something like this:

 

static unsigned char iDataBytes[]={0,1,2,3,4,5,6,7,8,9,10}; 

int MyFunnyFunc(unsigned char *buffer, int *length) {
if (maxLength > sizeof(iDataBytes))
maxLength = sizeof(iDataBytes))
memcpy(buffer, iDataBytes, maxLength);
return maxLength;
}

 

Working safely with pointers that are passed across domain borders (LabVIEW<->C runtime) is very tricky and error prone so it is better to simply use the standard C model where the caller provides all the buffers necessary and the callee fills them accordingly.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 18
(3,707 Views)