Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

c to c# help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    c to c# help

    I dont understand some of this code I am trying to convert

    Can anyone help?

    Code:
    void movingAverage(float * data, int windowSize) 
    // what does the * do?
    
     {
    float s1=0;
    int i;
    for (i=windowSize;i>0;i--)
    {
    s1 = s1 + *(data-i)/windowSize;
    //printf(" %f\n",*(data-i));
    }
    *(data) = s1;
    
    // and how does this * work?
    
    //printf(" %f\n",*data);
    }
    
    
    
    while(*(data+count)-meanSd > Tol || *(data+count)-meanSd < (-1.0)*Tol ) 
    // what does the * before data do?
    
    sdData = (float *)malloc(100000*sizeof(float));//
    // what is (float *)

    #2
    Hello tinkerz,

    The asterisk in this sample refers to a "pointer" inside of the "C" code. While this is not something we can support there is some examples that you may view to try to help you understand this.



    JCNinjaTrader Customer Service

    Comment


      #3
      Yes these snippets look a little bit disjointed.

      It looks like what is being passed in is a pointer to a chunk of memory containing floats (of size WindowSize which is total number of floats that will fit in the chunk of memory)

      C# doesn't support pointer syntax or pointers (which are really just memory addresses)

      The first snippet then fills up each float in the chunk of memory with a value.

      If I were you , I would just convert the allocated block into a collection such as a List<float> or ArrayList<float>. You can then just pass the list around and do whatever processing you need to do on it.

      // what does the * before data do?

      That * 'dereferences the address within the (). So what's within the () specifies which float location within the allocated block to look at the contents of.. then it subtracts a value from that float. Again, you can do the same with a collection class. Instead of float thefloat = *(data-somenumber)-othernumber;
      you could do something like:
      float thefloat = myfloatarray[theIndex]-othernumber;

      The second snippet allocates a 100000 floats in one shot... you can do the same thing with one of the collection classes.

      Anyway, hope that doesn't confuse you more.
      Last edited by BigWaveDave; 05-27-2014, 06:20 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X