473,738 Members | 3,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
Nov 17 '05 #1
2 2093
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
to****@mvps.org

Nov 17 '05 #2
"Tomas Restrepo \(MVP\)" <to****@mvps.or g> wrote in message news:<#g******* *******@TK2MSFT NGP14.phx.gbl>. ..
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.
Nov 17 '05 #3

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

Similar topics

4
52991
by: matty.hall | last post by:
I have two classes: a base class (BaseClass) and a class deriving from it (DerivedClass). I have a List<DerivedClass> that for various reasons needs to be of that type, and not a List<BaseClass>. However, I need to cast that list to a List<BaseClass> and it is not working. The code is below. I get the following exception: "Unable to cast object of type 'System.Collections.Generic.List`1' to type 'System.Collections.Generic.List`1'." ...
6
13916
by: Jeff.Boeker | last post by:
I'm learning a lesson in how I need to be more specific :) In C++ I can resize a vector and it will allocate memory and it will call the default constructor if necessary (or I can supply an instance for the copy constructor). For example: C++ vector<classvClass;
9
7904
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private List<as a property. Consider the example below, the class "ListTest" contains a private "List<>" called "strings" - it also provides a public method to add to that list,
0
1752
by: Iron Moped | last post by:
I'm airing frustration here, but why does LinkedList<not support the same sort and search methods as List<>? I want a container that does not support random access, allows forward and reverse traversal and natively supports sorting, i.e., STL's list<T>. There isn't even a set of algorithms that would allow me to easily sort a generic collection. System.Array has a robust set of static algorithms, why not extend this to ICollection?
44
39178
by: Zytan | last post by:
The docs for List say "The List class is the generic equivalent of the ArrayList class." Since List<is strongly typed, and ArrayList has no type (is that called weakly typed?), I would assume List<is far better. So, why do people use ArrayList so often? Am I missing somehing? What's the difference between them? Zytan
56
5201
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be checked on each iteration, since the Count changes as you delete elements. I would think it is guaranteed to be computed each time, and not cached. So, is this the best way?
45
18892
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies of their elements? Why can't I change the element itself? class Program { private struct MyStruct
35
5893
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the list. That part makes a reasonable amount of sense, as you can't actually take items away from an Array. However, there doesn't seem to be a way to perform the same operation in one fell swoop on a List<>. For example:
2
6159
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists, like List<char>. What I have working is : Type type = newObj.GetType(); //newObj is what I'm trying to dump
11
5010
by: paul.gibson | last post by:
A simple code example is easier than trying to describe the issue. I have: public class myClassA {
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.