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

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tomas Restrepo \(MVP\) (tomasr_at_mvps.org)
Date: 10/12/04


Date: Mon, 11 Oct 2004 19:36:59 -0500

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).

-- 
Tomas Restrepo
tomasr@mvps.org


Relevant Pages

  • List<t> generic type - Fastest way to copy into an unmanaged array?
    ... floats into an unmanaged array of floats. ... As far as the managed collection is implemented, ... fast way of copying a tradional managed array into an unmanaged array. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: List<t> generic type - Fastest way to copy into an unmanaged array?
    ... >> floats into an unmanaged array of floats. ... >> As far as the managed collection is implemented, ... type boxing/unboxing. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Getting a function to return an array
    ... I am trying to write a function which takes several floats as ... then returns 1x6 array of floats. ... The "unsafe" way to have that agreement is ...
    (comp.lang.c)
  • Re: converting to bits
    ... > Does C have some handy functions to convert chars, ints and floats to bit ... what type of array would you want to store ...
    (comp.lang.c)
  • Re: optimizing simple-arrays
    ... I'd expect your get-floatN routines to ... have to perform the array lookup at each reference, ... You might do better, also, to have maxvalue as single floats ... > function was the exact bottleneck, so I just optimized the whole thing ...
    (comp.lang.lisp)