473,480 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2703
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
8768
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
12660
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
11593
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
390
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
1925
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
5714
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
6340
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
1531
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
2857
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
7039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
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...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.