469,963 Members | 1,806 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Implementing Memcpy in C#

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
Nov 17 '05 #1
3 9907

"Vidya Bhagwath" <vi************@gmail.com> wrote in message
news:85**************************@posting.google.c om...
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.
Nov 17 '05 #2
> 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])

Nov 17 '05 #3
"Lebesgue" <no****@spam.jp> wrote in message news:<ue**************@TK2MSFTNGP15.phx.gbl>...
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.
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by franky.backeljauw | last post: by
5 posts views Thread by manya | last post: by
33 posts views Thread by Case | last post: by
6 posts views Thread by myhotline | last post: by
70 posts views Thread by Rajan | last post: by
18 posts views Thread by Mark | last post: by
7 posts views Thread by Amar Kumar Dubedy | last post: by
11 posts views Thread by mathieu | last post: by
2 posts views Thread by ssubbarayan | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.