Implementing Memcpy in C#

V

Vidya Bhagwath

Hello Experts,
I am porting a c++ code into c#.There are 3 structures, as explained
below.
typedef struct
{
unsigned char ByteCount;
unsigned short RegVals[10];
} WRITE_INFO;

typedef struct
{
unsigned short VarAddress;
unsigned short data[256];
}USER_PASSED_INFO;

typedef struct
{
WRITE_INFO WriteRegInfo;
USER_PASSED_INFO UserPassedInfo;
}LINKINFO;

LINKINFO Info;

My code uses the memcpy in the following fashion.

memcpy(Info.WriteRegInfo.RegVals[2], &Info.UserPassedInfo.data[2],
Info.WriteRegInfo.ByteCount );

As I know there is no code for memcpy in the C#. So how can I port the
above code into the C#. I am new to C#. I don't know much regarding
the C#. So can anybody tell me how exactly I can implement the above
line of code in C#.
Thanks in Advance for any help.
Regards,
Vidya
 
W

Willy Denoyette [MVP]

Vidya Bhagwath said:
Hello Experts,
I am porting a c++ code into c#.There are 3 structures, as explained
below.
typedef struct
{
unsigned char ByteCount;
unsigned short RegVals[10];
} WRITE_INFO;

typedef struct
{
unsigned short VarAddress;
unsigned short data[256];
}USER_PASSED_INFO;

typedef struct
{
WRITE_INFO WriteRegInfo;
USER_PASSED_INFO UserPassedInfo;
}LINKINFO;

LINKINFO Info;

My code uses the memcpy in the following fashion.

memcpy(Info.WriteRegInfo.RegVals[2], &Info.UserPassedInfo.data[2],
Info.WriteRegInfo.ByteCount );

As I know there is no code for memcpy in the C#. So how can I port the
above code into the C#. I am new to C#. I don't know much regarding
the C#. So can anybody tell me how exactly I can implement the above
line of code in C#.
Thanks in Advance for any help.
Regards,
Vidya

There is no need to use structures for this in C#, use classes.
You can use Array.Copy to copy sections from one array to another.

Willy.
 
L

Lebesgue

memcpy(Info.WriteRegInfo.RegVals[2], &Info.UserPassedInfo.data[2],
Info.WriteRegInfo.ByteCount );

simply Info.UserPassedInfo.Data[2] = Info.WriteRegInfo.RegVals[2]
should do the trick in C#, I believe
(assuming Info.UserPassedInfo.Data is an array of the same type as
RegVals[2])
 
V

Vidya Bhagwath

Lebesgue said:
memcpy(Info.WriteRegInfo.RegVals[2], &Info.UserPassedInfo.data[2],
Info.WriteRegInfo.ByteCount );

simply Info.UserPassedInfo.Data[2] = Info.WriteRegInfo.RegVals[2]
should do the trick in C#, I believe
(assuming Info.UserPassedInfo.Data is an array of the same type as
RegVals[2])

Hai All,
I was sucessfully able to port the code
"memcpy(Info.WriteRegInfo.RegVals[2], &Info.UserPassedInfo.data[2],
Info.WriteRegInfo.ByteCount )" into Visual C#.NET by following your
suggestions.Thank you very much for your guidance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top