Questions from a "dummy" - page 126

 
Renat:

Since when are all arrays static, and all sizes and indices static too?

Since arrays are almost always dynamic and indexes are variables, no serious static checks can be made at the moment of a call. The only checks left to do are meta/rtti checks and that is why it is so important to have access to the entire object/description and not work on the off chance with a piece of memory.

So, let's go in order. For static arrays, everything is easy to check at compile time, right?

For dynamic ones (which have hidden objects!), there is meta-information in runtime, right? There is! Of course there is.

All that remains is to specify the run-time checks in the executable code of the function being compiled. And that's it!

And I'm not saying that it's a piece of cake. Well, Slava (Stringo) knows his stuff too. Who has it easy nowadays, anyway? :)

// After all: it's all done in fours.

// If they already have dynamic arrays, use the meta-information they carry with them everywhere!

// Having it, you can do even wonderful things (like let the user to pass arrays of unknown dimension).

// And in mql5(!), you cannot even pass a two-dimensional array with both unknowns into a function.

// Even in antique toad you can do it. :))

 
Renat:

Don't worry, everything has been thought out a long time ago.

The consequences of breaking protection principles we know very well - it's the "in April we fixed 12 more critical bugs allowing to break out of the virtual machine and get control over the system" way.

I'm not bothered. The consequences of this particular solution, don't even smell like "control of the system". I didn't ask you for any such function pointers. The most it can do is crash "someone else's" memory if it's out of the array's range incorrectly controlled.
 
MetaDriver:

1. That was my suggestion to introduce naming and hence rigid typing, especially since it is the only place not covered by naming typing, hence fits well with the ideology of universalization of language entities.

2. All the same: firstly, it is crooked, and secondly, it is not universal at all. Suggest a way(1) to copy a two-dimensional mql-array into an OpenCL buffer without unnecessary rewriting and wrapping into structures, or(2) using (for speedy use) your own function ArrayCopy(...) for non-dimensional arrays.

// Sorry for the abruptness of the previous post. Really unnecessary. I got excited at "let's not complicate things". As it just leads to complications.

2a. I think your "one-dimensionality constraint" for functions like ArrayCopy() can be softened painlessly in many cases with one elementary clause in the comments: "The function works with multidimensional arrays as well, provided the multidimensional array is copied in its entirety. "

That would eliminate a lot of problems. // But not all of them, of course.

There are two ways, one is to copy one-dimensional arrays separately, but that's no good, because the OCL interface will be cluttered with arrays,

The second way is to represent a one-dimensional array as a two-dimensional one because it will be passed to OCL by tape anyway. So it goes like this. By the way, the very data moves when the dimension is changed could be done in OCL by copying a part of the array; it all depends on the size and whether it is cost-effective.

class CArrayTwo_merniy
  {
   float             a[];
   int               size_i;
   int               size_j;
public:
                     CArrayTwo_merniy(void){size_i=0;size_j=0;};
                    ~CArrayTwo_merniy(void){};
   void              Resize(int i,int j)
     {
      int size;
      if(j<size_j)// если уменьшаем j размер массива
        {
         for(int l=1;l<i;l++)
            for(int k=0;k<j;k++)
               a[l*i+k]=a[l*size_i+k];
         size=ArrayResize(a,i*j);
         if(size==i*j)
           {size_i=i; size_j=j;}
         return;
        }
      else // иначе, если увеличиваем j размер массива
        {
         size=ArrayResize(a,i*j);
         if(size==i*j)
           {
            for(int l=i-1;l>=0;l--)
               for(int k=j-1;k>=0;k--)
                  a[l*i+k]=a[l*size_i+k];
            size_i=i; size_j=j;
           }
        }
     };
   void set(int i,int j,float v)
     {
      if(i*size_i+j>=0 && i*size_i+j<size_i*size_j)a[i*size_i+j]=v;
      else Print("Ошибка set ["+i+":"+j+"]");
     };
   float get(int i,int j)
     {
      if(i*size_i+j>=0 && i*size_i+j<size_i*size_j)return(a[i*size_i+j]);
      else {Print("Ошибка get ["+i+":"+j+"]"); return(EMPTY_VALUE);}
     };
  };
//+------------------------------------------------------------------+
void OnStart()
  {
   CArrayTwo_merniy ar; string t;
   ar.Resize(3,3); int cnt=0;
   for(int i=0;i<3;i++)for(int j=0;j<3;j++){ar.set(i,j,(float)cnt); cnt++;}
   t="исх ";for(int i=0;i<3;i++){for(int j=0;j<3;j++)t+="["+ar.get(i,j)+"]";t+=".";} Print(t);
   ar.Resize(5,5);
   t="5х5 "; for(int i=0;i<5;i++){for(int j=0;j<5;j++)t+="["+ar.get(i,j)+"]";t+=".";} Print(t);
   ar.Resize(3,3);
   t="3х3 ";for(int i=0;i<3;i++){for(int j=0;j<3;j++)t+="["+ar.get(i,j)+"]";t+=".";} Print(t);
  }
 
Urain:

There are two ways, one is to copy one-dimensional arrays separately, but it's no good, because the OCL interface will be cluttered with arrays,

The second way is to represent a one-dimensional array as a two-dimensional one because it will be passed to OCL by tape anyway. So it goes like this. By the way, the very data moves when the dimensionality is changed can be done in OCL by copying a part of the array; it all depends on the size and to what extent it is cost-effective.

многа многа букаф

I've had enough of all this. :) Occam is hysterical...

;)

Here I have a two-dimensional array. I have its sizeof(My2DArray). What else do I need to copy it into the buffer? Anyway, no one has even provided me with an offset in my array to make it a variable. So, no. First I have to rewrite it (which leads to lags), or write my own two-dimensional array. (!!) Oh, my gosh. And what's it for? To keep me safe. (!) That's it, I'm laughing. :)))

 
MetaDriver:

That's all I've had enough of. :) Occam is hysterical...

;)

:))

Frankly speaking, resizing overhead is huge, but you can cut it down by using OCL for these things.

But direct copying of a two-dimensional array into an OCL buffer.

And I wouldn't advise you to re-partition the array at every sneeze.

As it is, it's quite applicable.

 
MetaDriver:

That's all I've had enough of. Occam is hysterical...

;)

Come on, three set get and resize functions.

I wrote it for you on my knees while you've been moping around.

 
Urain:
Come on, that's a lot of words, three functions set get and Resize
It's cool, I bet. When they make us overloading operators (and don't forget to make operators "[ ]" and "=" overloadable, then we'll have fun. We will be able to sell our dynamic arrays in the market. And they will take it! And who will not take them - let's turn off gas transmission of multidimensional arrays into functions. :)
 
MetaDriver:
Cool, no doubt about it. When they make us operator overloading (and don't forget to make operator "[ ]" preloadable, then you'll be happy. We will sell our own dynamic arrays in the market. And they will take it! And who will not take it - let's turn off gas transmission of multidimensional arrays in functions. :)
We will not forget ;)
 
mql5:
We won't forget ;)
:))
 
MetaDriver:

I have a two-dimensional array. I have its sizeof(My2DArray). What else do I need to copy it to the buffer? Anyway, no one has even provided me with an offset in my array to make it a variable. So, no. First I have to rewrite it (which leads to lags), or write my own two-dimensional array. (!!) Oh, my gosh. And what's it for? So I can be safe. (!) That's it, I'm laughing. :)))

Dear Sir, watch the context.

1) When you jump from one controlled and safe environment to a completely uncontrolled raw buffer, it is you who is responsible for compatibility with that binary environment.

2) When you write code, you are responsible for the architecture of that code. And don't whine that "it's hard to put a horse and a doe in the same cart" when you use different structures.

3) I recommend that you read the description of CLBufferRead and CLBufferWrite - thanks to the universal void* reference, you can pass any type of reference to OpenCL. And there are offsets and sizes too.

uint  CLBufferRead(
   int          buffer,                    // хендл на буфер OpenCL
   const void&  data[],                     // массив значений
   uint         buffer_offset=0,           // смещение в OpenCL буфере в байтах, по умолчанию 0
   uint         data_offset=0,             // смещение в массиве в элементах, по умолчанию 0
   uint         data_count=WHOLE_ARRAY      // количество значений из буфера для чтения, по умолчанию весь буфер
   );
uint  CLBufferWrite(
   int          buffer,                    // хендл на буфер OpenCL
   const void&  data[],                     // массив значений
   uint         buffer_offset=0,           // смещение в OpenCL буфере в байтах, по умолчанию 0
   uint         data_offset=0,             // смещение в массиве в элементах, по умолчанию 0
   uint         data_count=WHOLE_ARRAY      // количество значений из массива для записи, по умолчанию весь массив
   );

I can see that the subject is just scratched out of thin air.