473,554 Members | 3,144 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 2081
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
52943
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...
6
13909
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
7863
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...
0
1737
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...
44
39139
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
5113
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. ...
45
18797
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
5848
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...
2
6117
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
4995
by: paul.gibson | last post by:
A simple code example is easier than trying to describe the issue. I have: public class myClassA {
0
7584
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7783
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8023
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...
0
6129
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...
1
5426
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...
0
5144
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...
0
3548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1117
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
828
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...

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.