Array references - page 3

 

Holy crap -- the sizeof this structure --

struct ArrayStore
{
   long reserved;
   double x[];
};

60 bytes ) but that's crazy. That's 52 bytes to unscramble.

If you're interested, here's the initial code for digging

#import "msvcrt.dll"
  long memcpy(long &dst, long &src, int cnt);
  long memcpy(uchar &dst[], long &src, int cnt);
#import

struct ArrayStore
{
   long reserved;
   double x[];
};

#define N 60
// sizeof(ArrayStore) == 60

void OnStart()
{
   ArrayStore store;
   ArrayResize(store.x, 0x11, 0x22);
   store.reserved = 0xFF;
   
   uchar array[N];
   ArrayInitialize(array, 0);
   
   memcpy(array, store.reserved, N);
   
   string s;
   for (int i = 0; i < N; i++)
   {
      s = s + " " + StringFormat("%.2X", array[i]);
   }
   Print(s);
}
 
ArrayStore::double x[];
I'm not getting the gist of this parameter...
 
sergeev:
I don't seem to get the gist of this parameter...

What about getting the address of the first element of the array:

long ArrPtr = memcpy(Arr[0], Arr[0], 1);


doesn't work?

 
MetaDriver:

What about getting the address of the first element of an array:

long ArrPtr = memcpy(Arr[0], Arr[0], 1);


doesn't work?

works of course.

but I still don't understand why

ArrayStore::double x[];
 
sergeev:

It works, of course.

But I still don't understand why

I don't get that either. :)
 
MetaDriver:
I don't get it either. :)

Come on.

I'll repeat the task again. With time O(1) relative to time series size make a reference to it. I.e. copying of array is forbidden a priori.

The only way is to fetch the array structure. So, forcing time series pointer instead of array pointer, along with some parameters, to make structure think it's ok.

The size of the arraystructure is 52 bytes, 8 of which (presumably) is actually a pointer, the rest are settings, like size, reserves, AsSeries properties, etc. (Win7x64)

Now the task is to unpack the structure and learn how to slip it adequate data.

Документация по MQL5: Основы языка / Операции и выражения / Другие операции
Документация по MQL5: Основы языка / Операции и выражения / Другие операции
  • www.mql5.com
Основы языка / Операции и выражения / Другие операции - Документация по MQL5
 
sergeev:

works, of course.

It works of course, but this way we get a pointer to the data, we can't replace the pointer, we can only replace the data, so ... we need to go deeper (c)
 

either that or I don't understand what's needed.

In the first post, you set the problem:

Some sort of array reference, like this:

I showed you that memcpy successfully gets a pointer to the array.

Then use the same memcpy and get the data.


So what do you really need? Why are you building some kind of structure here? What does it have to do with a pointer to an array?

 
sergeev:

Then use memcpy and retrieve the data.

Slowly. All dll functions are called via a wrapper.

I need a normal array without copying.

Take a look at the first post. It has a very precise code that says exactly what I want.

 
TheXpert:

Slowly. All dll functions are called via a wrapper.

I need a normal array without copying.

Look at the first post. There's a very precise code that says exactly what I want.

It's simple:) Make a full-fledged time-series array in Quartet (yours is the ninth) and the golden key is in your pocket:)

They'll give you a slap on the wrist, imho. You can't hack the sacred cow.