List<t> generic type - Fastest way to copy into an unmanaged array?

D

Daniel Mori

Hi, Im hoping someone can give me some advice.
Im doing some development using VS Whidbey 2005 beta 1.

Im about to implement some highly time critical code related to a
managed collection of floats.

I basically require the fastest way to convert a managed array of
floats into an unmanaged array of floats.

As far as the managed collection is implemented, ive read that the
following would be the most type-safe and efficient (no
boxing/unboxing):

List<float> myFloats

However, Ive also read that the Marshal.Copy method is an extremely
fast way of copying a tradional managed array into an unmanaged array.
But if i do this method (i,e use a tradional .net array), I have the
boxing/unboxing issues.

For this particular case, I must sacrifice all I can for conversion
speed.

Can anyone recommend the fastest way to store and convert an array of
floats (managed -> unmanaged)?

thanks for reading.
 
T

Tomas Restrepo \(MVP\)

Daniel,
Hi, Im hoping someone can give me some advice.
Im doing some development using VS Whidbey 2005 beta 1.

Im about to implement some highly time critical code related to a
managed collection of floats.

I basically require the fastest way to convert a managed array of
floats into an unmanaged array of floats.

As far as the managed collection is implemented, ive read that the
following would be the most type-safe and efficient (no
boxing/unboxing):

List<float> myFloats

However, Ive also read that the Marshal.Copy method is an extremely
fast way of copying a tradional managed array into an unmanaged array.

It is indeed.
But if i do this method (i,e use a tradional .net array), I have the
boxing/unboxing issues.

Huh? Why boxing here? As long as you use an array of float, you won't need
boxing/unboxing. Granted, you'll end up copying a value here and there from
the stack to the managed heap where the array is stored, but it definitely
does *not* imply boxing at all (unless you for some reason declare the array
as Object* __gc[], which you probably aren't doing).
 
D

Daniel Mori

Tomas Restrepo \(MVP\) said:
Daniel,
Hi, Im hoping someone can give me some advice.
Im doing some development using VS Whidbey 2005 beta 1.

Im about to implement some highly time critical code related to a
managed collection of floats.

I basically require the fastest way to convert a managed array of
floats into an unmanaged array of floats.

As far as the managed collection is implemented, ive read that the
following would be the most type-safe and efficient (no
boxing/unboxing):

List<float> myFloats

However, Ive also read that the Marshal.Copy method is an extremely
fast way of copying a tradional managed array into an unmanaged array.

It is indeed.
But if i do this method (i,e use a tradional .net array), I have the
boxing/unboxing issues.

Huh? Why boxing here? As long as you use an array of float, you won't need
boxing/unboxing. Granted, you'll end up copying a value here and there from
the stack to the managed heap where the array is stored, but it definitely
does *not* imply boxing at all (unless you for some reason declare the array
as Object* __gc[], which you probably aren't doing).


You're quite right. I mis-read documentation on array and collection
type boxing/unboxing.

Thankyou for your assistance.
Regards.
 

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