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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      175 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      331 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      253 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      356 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      183 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X