How do i retain the data value of static variable despite the program restarting?
How do i retain the data value of static variable despite the program restarting?
Loading saved threads...
Renz Carillo · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Renz Carillo
Original post: https://stackoverflow.com/questions/66783247
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have a static variables on several of my functions, how do i retain the value of these static variables when an unexpected restart in program occurs?
Quote
Report
SergeyA · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: SergeyA
Original post: https://stackoverflow.com/a/66783675
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
There is no way to do this in standard C++. However, there is a way of doing it with OS-specific tools, and most often, the best tool is a memory backed by permanent storage - a memory-mapped file.
All OSes I have ever worked with support memory-mapped files, although specifics might differ between OSes.
Unfortunately, using conventional files to store variables like that is quite inconvenient, as you'd have to explicitly save the value every time you change it, and make sure the buffers are flushed - otherwise you can't guarantee that the value is preserved after ungraceful exit - and that would be quite detrimental to performance.
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/66803548
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
If you are using MQL4 or MQL5 (which I assume you are by the tags on your post), simply use GlobalVariables.
MQL4:
https://book.mql4.com/variables/globals
MQL5:
https://www.mql5.com/en/docs/globals
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: SergeyA Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/66783675 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. There is no way to do this in standard C++. However, there is a way of doing it with OS-specific tools, and most often, the best tool is a memory backed by permanent storage - a memory-mapped file. All OSes I have ever worked with support memory-mapped files, although specifics might differ between OSes. Unfortunately, using conventional files to store variables like that is quite inconvenient, as you'd have to explicitly save the value every time you change it, and make sure the buffers are flushed - otherwise you can't guarantee that the value is preserved after ungraceful exit - and that would be quite detrimental to performance.
Checking account access…