Print("Error in ", LOCATION)is expanded toPrint("Error in ",__FILE__" : " STR(__LINE__))
STR(__LINE__)has no stringification operation, i.e. there is no#xin it's expansion, but there is anx , so it has to evaluatexand input the value of __LINE__ toST2for stringification. It expands toST2(11)which in turn will stringify the number 11, since it is using#x
So, techniqually speaking:
Using a single layer indirectionST2(x) #xstringifies the inputtedmacro's name(for example:"__LINE__")
but by using double layers, it will stringify the inputtedmacro's value. (for example: "11")
struct STRUCT
{
int Value;
void Func( int ) {}
};
#define MACROS(A) Struct##A
#define MACROS2(A) MACROS(A)voidOnStart()
{
STRUCT Struct;
MACROS(.Value) = 0; // The first entry is OK.
MACROS(.Func(0)); // The second entry is OK.MACROS2(.Func(MACROS2(.Value))); // First and second entry together - undeclared identifier.
}
Solution: use a 2nd level macro (for indirection).
If you press Stop during optimisation, the descriptors of interrupted passes remain open, because code execution is strictly interrupted, preventing the logic of closing descriptors - CloseHandle - from being executed.
Moreover, this situation may occur during debugging, when debug closure is in progress. In general, there are scenarios in which descriptors are not closed.
I searched for a long time on the Internet for ways to close descriptors. In particular, in the case of using File Mapping.
I have a series of Slave exe's controlled by a Master exe via usage of Named Shared Memory created with CreateFileMapping() and MapViewOfFile(). I was debugging the Master via Visual Studio, and when I got what I needed I simply told Visual Studio to "stop debugging". Bad move, because that Named Shared Memory was left active, and it is still...
fxsaber # : Is it possible to free memory/file if open descriptors are hanging? Right now the problem is solved only by reloading the process - Terminal.
So, what happens at Print("Error in ", LOCATION)
Print("Error in ", LOCATION) is expanded to Print("Error in ", __FILE__ " : " STR(__LINE__))
STR(__LINE__) has no stringification operation, i.e. there is no #x in it's expansion, but there is an x , so it has to evaluate x and input the value of __LINE__ to ST2 for stringification. It expands to ST2(11) which in turn will stringify the number 11, since it is using #x
So, techniqually speaking:
Forum on trading, automated trading systems and testing trading strategies
Features of the mql5 language, subtleties and tricks
amrali, 2025.11.04 11:40
Solution: use a 2nd level macro (for indirection).
This was discussed before here and here.
Output:
If you press Stop during optimisation, the descriptors of interrupted passes remain open, because code execution is strictly interrupted, preventing the logic of closing descriptors - CloseHandle - from being executed.
Moreover, this situation may occur during debugging, when debug closure is in progress. In general, there are scenarios in which descriptors are not closed.
I searched for a long time on the Internet for ways to close descriptors. In particular, in the case of using File Mapping.
Found only a formulation of the same problem without an answer.
For example, if the process was interrupted before CloseHandle, such a function will always return true on the next runs.
Is it possible to somehow free memory/file in case of open handles hanging? Now the problem is solved only by reloading the process - Terminal.
Is it possible to free memory/file if open descriptors are hanging? Right now the problem is solved only by reloading the process - Terminal.
Conclusion:
Can an existing Handle be reused?
Is it possible to free memory/file if open descriptors are hanging? Now the problem is solved only by reloading the process - Terminal.
If you press Stop during optimisation, the descriptors of interrupted passes remain open
Handle command line utility from Sysinternals won't help?
If you need to use WinAPI, you can do UnmapViewOfFile and CloseHandle (both are required). I don't know in detail, I haven't analysed it.
The Handle command line utility from Sysinternals won't help?
You need to use WinAPI.
If you need to use WinAPI, you can do UnmapViewOfFile and CloseHandle (both are required). I don't know in detail, I haven't analysed it.
Here you can find more details.