473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Raw copy from array of byte to array of Int16

TDH
Hi,

I need to do a raw copy of a byte array to an Int16 array.
For e.g., I have an byte array which has length 100, and I
need to copy this to an Int16 array that has length 50. So
2 elements in the byte array gets copied to 1 element in
the Int16 array.

In VB6, this was easily done using CopyMemory. I need
something in .NET that works as fast as CopyMemory. I
can't loop thru each element in the array because the
array could have thousands of elements and looping would
be too slow.

In VB.Net, the CopyMemory function no longer works
correctly. I can call the function, but it does not
actually perform the copy. I think there are some
marshaling calls that would eventually make it work, but
I'd prefer to find a native .NET solution.

I have looked at the members of the Array class, but they
only allow copying item-to-item. They don't allow raw copy
so that 2 elements of the byte array would go into 1
element of the Int16 array.

Does anybody know how to do this kind of raw copying from
one array to another?

Thanks.

TDH
Jul 21 '05 #1
2 2701
TDH <jm@penwoodtech.com> wrote:
I need to do a raw copy of a byte array to an Int16 array.
For e.g., I have an byte array which has length 100, and I
need to copy this to an Int16 array that has length 50. So
2 elements in the byte array gets copied to 1 element in
the Int16 array.


Have a look at Buffer.BlockCopy.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thanks. That did the trick.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
TDH <jm@penwoodtech.com> wrote:
I need to do a raw copy of a byte array to an Int16 array.
For e.g., I have an byte array which has length 100, and I
need to copy this to an Int16 array that has length 50. So
2 elements in the byte array gets copied to 1 element in
the Int16 array.


Have a look at Buffer.BlockCopy.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
9
by: Charles Law | last post by:
Suppose I have a structure Private Structure MyStruct Dim el1 As Byte Dim el2 As Int16 Dim el3 As Byte End Structure I want to convert this into a byte array where
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
2
by: TDH | last post by:
Hi, I need to do a raw copy of a byte array to an Int16 array. For e.g., I have an byte array which has length 100, and I need to copy this to an Int16 array that has length 50. So 2 elements...
5
by: Rain | last post by:
simple question: i have a byte array.. how do i write to the console the last 2 bytes of the byte array? thanks in advance
3
by: tash.robinson | last post by:
I have been pulling my hair out with this and have searched and found some solutions but I can't seem to get them to work as expected. I have a structure, which I have declared explicitly using...
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
6
by: Scott Townsend | last post by:
So here is a noob question.. I'm looking to have Int16 SQLCmd Byte Array that is a Total of 256 Bytes PARMS Byte Array that is a Total of 1080Bytes UNUSED Byte Array that is a Total of...
10
by: ShadowLocke | last post by:
I'm looking for a better understanding of whats going on with the code i write. I have come across something that I thought I understood but its not working as expected. Its hard to explain so let me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.