473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Queue.ToArray into float []?

I have a System.Collections.Queue instance filled with floats and I would
like to convert it into a float [] because a third party plotting package
requires it. I have tried casting Queue.ToArray() via

float [] a = (float []) Queue.ToArray();
float [] a = Queue.ToArray() as float[]

no luck. Do I have to extract out each element from the Queue and place
them into my own allocated array?

float [] a = new float[Queue.Count];
int i=0;
foreach(float v in Queue) { a[i] = v; i++;}

Is this very inefficient?

Thanks
Nov 17 '05 #1
3 4501
My understanding is that the ToArray method of the Queue class returns
an object array.

Object[] myStandardArray = mySourceQ.ToArray();

with that in hand, you ought to be able to do:
(float)myStandardArray[i]

Nov 17 '05 #2
troy anderson wrote:
I have a System.Collections.Queue instance filled with floats and I would
like to convert it into a float [] because a third party plotting package
requires it. I have tried casting Queue.ToArray() via

float [] a = (float []) Queue.ToArray();
float [] a = Queue.ToArray() as float[]

no luck. Do I have to extract out each element from the Queue and place
them into my own allocated array?

float [] a = new float[Queue.Count];
int i=0;
foreach(float v in Queue) { a[i] = v; i++;}

Is this very inefficient?

Thanks


Did you check out the CopyTo method?

John Davison
Compass Engineering Group
Nov 17 '05 #3
The problem is that your Queue is holding "boxed floats" (value-type
floats converted in refernce-type objects). ToArray (and I suspect CopyTo)
is just copying to copy that objects without unboxing them. However the
float[] needs them unboxed.
float [] a = new float[Queue.Count];
int i=0;
foreach(float v in Queue) { a[i] = v; i++;}

Is this very inefficient?
No, that's fine. It's pretty much just what ToArray is doing.

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"troy anderson" <ta******@hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl... I have a System.Collections.Queue instance filled with floats and I would
like to convert it into a float [] because a third party plotting package
requires it. I have tried casting Queue.ToArray() via

float [] a = (float []) Queue.ToArray();
float [] a = Queue.ToArray() as float[]

no luck. Do I have to extract out each element from the Queue and place
them into my own allocated array?

float [] a = new float[Queue.Count];
int i=0;
foreach(float v in Queue) { a[i] = v; i++;}

Is this very inefficient?

Thanks

Nov 17 '05 #4

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

Similar topics

2
by: Sunny | last post by:
Hi, I have a small function, that returns a string, inside the function, there is an arraylist, being processed. At the end of the function all the elements of the ArrayList are copied to my...
2
by: Grey | last post by:
Dear all I want to know that how to use ToArray function in ArrayList. I have an ArrayList which is storing string, Actually, I want to use the Join method, so I think I need to convert the...
4
by: Derrick | last post by:
If i have an ArrayList, add a bunch of MyClass classes to it, how do I get a MyClass out of it? I've tried: MyClass clses = ArrayList.ToArray(typeof(MyClass)); but get errors about not being...
2
by: Dirk | last post by:
Hello The following code does not work ArrayList __gc* allControls = new ArrayList(); ..... // put some Controls in allControls .... Control __gc* arr = dynamic_cast<Control...
19
by: ern | last post by:
I need a FIFO queue of size 20, to keep track of a running average. Once the queue is full with 20 values, I want to take the sum/20 = AVERAGE. Then when a new value comes in, I want: (Old Sum...
3
by: eric.boissard | last post by:
Hello, I managed to implement the AStar algorithm, however I have some trouble using the priority queue, and the 'compare' function. Here is my 'Waypoint.h' header file: class Waypoint {...
4
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the...
3
by: Michael Howes | last post by:
I have many double that each have a few thousand numbers in them. I need to concatenate groups of these double arrays into a new set of double. I don't know the total # of points. I thought it...
19
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
I am currently designing a synchronized queue used to communicate between threads. Is the code given below a good solution? Am I using mutex lock/unlock more than needed? Are there any resources...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.