Need fast memory access - ArrayCopy

 

Hello,

I have about 1-50 mb data in memory and for access/analysis I need fast access to this memory.
I have to inserts my Array of structs (sometimes 60 double pairs) in the large Array, move memory
around and so on.

struct stMyStruct
{
   double dblD1;
   double dblD2;
};
...

   stMyStruct mySt;
   mySt.dblD1 = 0.3;
   mySt.dblD1 = 9.67;
   
   double dblMem[];
   ArrayResize(dblMem, 4);

/* not working:
   ArrayCopy(dblMem, mySt, 0, 0, 1);
   dblMem = mySt;
   dblMem = dynamic_cast<stMyStruct *>(&mySt);
*/

Because we've no memcpy I like to use ArrayCopy but I can't get a working cast.

So I'm looking for a way to cast my struct to any position inside the large double Array.

Thanks for helping.

 
Mighty7:

Hello,

I have about 1-50 mb data in memory and for access/analysis I need fast access to this memory.
I have to inserts my Array of structs (sometimes 60 double pairs) in the large Array, move memory
around and so on.

Because we've no memcpy I like to use ArrayCopy but I can't get a working cast.

So I'm looking for a way to cast my struct to any position inside the large double Array.

Thanks for helping.

a double value is not going to be able to contain a structure of two doubles it won't fit no matter how you cast it

 

Thanks for your answer. A double struct has 16 Bytes and I can't copy the content to a dynamic array of doubles with ArrayCopy?

 
Mighty7:

Thanks for your answer. A double struct has 16 Bytes and I can't copy the content to a dynamic array of doubles with ArrayCopy?

ArrayCopy needs a source array and a destination array,  your structure is not an array.

what are you really trying to achieve? how does moving the values from structure to a double array make it any faster access?

 
Mighty7:

Hello,

I have about 1-50 mb data in memory and for access/analysis I need fast access to this memory.
I have to inserts my Array of structs (sometimes 60 double pairs) in the large Array, move memory
around and so on.

Because we've no memcpy I like to use ArrayCopy but I can't get a working cast.

So I'm looking for a way to cast my struct to any position inside the large double Array.

Thanks for helping.

You could do this:

struct stMyStruct
{
   double dblD[];
};

int OnInit()
  {
   stMyStruct mySt;
   ArrayResize(mySt.dblD, 2);
   mySt.dblD[0] = 0.3;
   mySt.dblD[1] = 9.67;
   
   double dblMem[];
   ArrayResize(dblMem, 4);

   ArrayCopy(dblMem, mySt.dblD, 0, 0, 2);
   ArrayPrint(dblMem); // 0.30000  9.67000 +0.00000 +0.00000
 
lippmaje:

You could do this:

You can move a struct to a bytearray with StructToCharArray if that helps.
 

The structure is delivered from MT5 and I have to deal with it. Normally I could deal direct with these data but
I need no remove some elements (build a new struct) and then store them in memory for access.

But it seems I found a solution. I'll be back if it's not working. Thanks for trying to help.
 

lippmaje: yes, I know. But thanks


Laszlo Tormasi: oh, I did not know that. This is a very good point and could solve my problem. Thanks.

 

StructToCharArray  is not really what I want because I copies the Elements to the struct. 
I should have known that right away. A cast would only give me access in form of the struct
without cpu cycles or memory movement.

 
Try a union.
Reason: