Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:08:42+00:00 2026-05-24T13:08:42+00:00

First of all I am running this on a Mobile Device using CE6.5. I

  • 0

First of all I am running this on a Mobile Device using CE6.5. I have an ArrayList of data that are ints and for graphing purposes I want to convert in order the number it is into the list and the int value into the x and y values for a Point. Put all those points into a Point Array then use bufferedGraphics.DrawLines to draw that onto the form. I have a way of doing that that seems to work pretty fast but not sure if this is the best way. Any suggestions or improvements to this code?

Oh yeah dataList is usually about 450 or more depending on screen size and rotation.

public Point[] toPointArray(int w, int h) {
      Point[] p;
      int val;

      p = new Point[dataList.Count];
      for (int i = 0; i < dataList.Count; i++) {
          val = (int)dataList[i];
          if (i < p.Length)
               p[i] = new Point(i, h - (val * h) / range + (min * h) / range);
      }
      return p;
}

Some of my data coming is updating the dataList at 256 times per sec, so concerns of overwriting are there but so far this seems to work even at these speeds.

Here are some speed values on how fast this is currently, time is in secs:

Time to complete 0.000588
Time to complete 0.0005886154
Time to complete 0.0005846154
Time to complete 0.0005870769
Time to complete 0.0005830769
Time to complete 0.0005806154
Time to complete 0.0005981539
Time to complete 0.0007206154
Time to complete 0.0005836923
Time to complete 0.001039077

After taking suggestions from the answers below here is what my code looks like now and I am getting 0.00047 secs in execution time on the average. dataList is a global that is now a List instead of ArrayList, the (int) cast was taking up a quarter of the original processing time.

   List<int> dataList = new List<int>();

   public Point[] toPointArray(int w, int h) {
        Point[] p = new Point[dataList.Count];
        for (int i = 0; i < dataList.Count; i++) {
            p[i] = new Point(i, h - (dataList[i] * h) / range + (min * h) / range);
        }

        return p;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:08:43+00:00Added an answer on May 24, 2026 at 1:08 pm

    1) Declare the variables at the same place you use them. No need to declare Point[] a separately (it’s created right after that), and no reason to declare int val separately (it’s not used outside the loop and there are no performance penalties for declaring it where you use it).
    2) You know that i is < p.Length (assuming single-threaded application), remove the check.
    3) Use LINQ
    4) Use Microsoft’s suggested naming standards (ProperCase for methods)
    5) Use better variable names
    6) Use better method names – this method isn’t converting it to an array (or at least, that’s not the main purpose of the method)
    7) Use a typed datastore. We can’t see what dataList is, but you shouldn’t have to convert it to an int (unless it’s a long that you know is an int, or somesuch)

    If you can use LINQ, I haven’t looked over Yahia’s solution but it should work. If you can’t/don’t want to use LINQ, try:

    public Point[] ToPointGrid(int width, int height)
    {
      Point[] points = new Point[dataList.Count];
      for(int index = 0; index < dataList.Count; ++index)
      {
        points[index] = new Point(index, height - (dataList[index] * height) / range + (minimum * height) / range);
      }
      return points;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I have many Django instances setup and running like this. In
I have this query that's running too slow. I'm not sure what all info
First of all, before I begin, I am using VC++ 2008 professional, running an
First of all, apologize because I have seen some posts about this, but I
I have an old windows mobile application that the boss wants running on Windows
First of all, this isn't for a keylogger, it's for an input in a
First of all there is probably a question like this already but i couldn't
I'm running ImageMagick 6.7.4-0 and Imagick 3.0.1. I have all of the delegates necessary
Ok here goes. On my network I have a couple of pc's all running
First of all I have a simple ListView . Implementing the BaseAdapter and utilizing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.