I have left C/CC++ coding long back some where in 2001, No doubt that I need to refresh it.
But now I found the C/C++ interesting when Amibroker has nicely and safely played with array and pointers, unions and structures.
I have one doubt with the consideration of following line.
To the best of my memory and if I am not wrong, *float O is a Pointer pointing to some location of memory Address AND *(&O) is the value (Content) stored at that address.
CAN following line avoid multiple calls of gSite.GetStockArray( 0 ) if I want to copy values (content ) stored at *O without disturbing it, in case I change values stored at *xO, *yO, zO at later stage?
Can values (content) stored at *O be copied to *xO, *yO and *zO directly ?
This is not generally true. That would only work if you referred to single float value (4 bytes) via pointer, but in AmiBroker pointer to float typically points to ARRAY of floats and you can't copy entire array via *ptr in single assignment in C. Copying arrays in C typically involves using memcpy.
No. You are mixing two things. One thing is copying pointer (the one that you are getting via GetStockArray(). The other thing is copying content (array). These two are two completely different things. You can copy and use pointer to READ data as many times as you want. But if you want to MODIFY data you have to allocate memory for result and use allocated memory. GetStockArray is giving you READ-ONLY memory. And don't worry about the speed with pointers. GetStockArray is a super thin function that is pretty much equally fast as using pointer as it gets inlined by compiler anyway.
Your are right, I also tried a pointer to pointer in code DLL Compiled but returned zero in afl....
Neither it worked nor crashed...
Due to AFL I remember Clipper of 1990s on DOS. Clipper programmers were allowed to work with multidimensional arrays but there were no pointers , unions and structures like C/C++. There was MSC6.0 support for LARGE MODEL external third party Libraries which was used for additional development.
it appears Amibroker has some Assembly Code with C/C++
Now I will use gSite.GetStockArray only instead of trying to make copy of its output.
Thanx once again.
for( i = 1; i < BarCount; i++ )
output[ i ] = factor[ i ] * input[ i ] + ( 1 - factor[ i ] ) * output[ i - 1 ];
AMA logic / formula in AFLand AMA Function are giving same output.
so in DLL I can use this logic instead of CallFunction.
Now if I pass some other average or array in C/C++ to get AMA's out put do i need to set the first element of that array to 0 like AFL logic ?
Thanx for Reply.
I am learning ADK and now I am not in touch of C/C++ which I have left 15-20 years back.
But I am impressed with Amibroker's ADK/API methods which has encouraged me to polish my knowledge again. Actually it is easy to start with C again because of predefined enums, unions and structures in Amibroker's ADK Header Files.
What I have noted from your earlier advice that not to use CallFunction without reason, so I was trying to write AMA() in C.
But If my C Code is wrong how it gives correct result of inbuilt AMA function of Amibroker ?
I will also take care to post Code with provision of </> Button. I was trying to correct it but post was not published.
My old C code xAMA, 2) the in built AMA Function and 3) the corrected xAMA code by TJ ,all 3 were giving same output, so I was not able to find out the difference, but when I saw chart from beginning there was as an issue due to output.array=0;
So i corrected it as told by TJ.
Actually I was doing this for Another code given in examples that uses in build AMA in C