Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Quad, VoroneTZ, 1 invisible), 623 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
NumBars == 0 in INITRUN. Intended? #445987
10/01/14 14:35
10/01/14 14:35
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
http://zorro-trader.com/manual/en/mode.htm
INITRUN
First run of the script, before the price data is loaded. Can be used to initialize global and static variables.

NumBars
Total number of bars in the simulation, determined from StartDate and EndDate and from the available data in the price history files.
http://zorro-trader.com/manual/en/numbars.htm

I want NumBars to be initialized in INITRUN.
so I can malloc arrays that are based on the size of the test period.

As I work-around, I need to wait for the second bar (SECONDRUN ?) before NumBars has a useful value.
Code:
function run() {
  static var* final_report_data = NULL;
  if (is(INITRUN)) {
  } else {
    if (final_report_data == NULL) {
      final_report_data = malloc(NumBars * sizeof(var));
      memset(final_report_data, 0, NumBars * sizeof(var));
    }
  }
  ...
  if (final_report_data != NULL) {
     final_report_data[x] = ...
  }
}


Re: NumBars == 0 in INITRUN. Intended? [Re: GPEngine] #445989
10/01/14 15:00
10/01/14 15:00
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Yes. As you can not initialize a variable before knowing its content, your code is the best and correct way for allocating the array.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1