Populating an array of dynamic size on each run of run()

Posted By: strimp099

Populating an array of dynamic size on each run of run() - 02/04/21 09:08

Greetings,

My intent is to populate an array with option strikes for daily run. However I receive a syntax error when attempting to create an array like this:

Code
var strikes[NumContracts];


presumably because arrays are static and cannot be redeclared. According to the manual, using malloc to allocate space dynamically is slow. So something like this:

Code
var strikes = malloc(NumContracts*sizeof(var));


Is not recommended

Is there a standard way to dynamically create arrays during each run?
Posted By: Grat

Re: Populating an array of dynamic size on each run of run() - 02/04/21 10:48

may be series?
Posted By: strimp099

Re: Populating an array of dynamic size on each run of run() - 02/04/21 11:30

I’m trying to create an array of strikes each day. Can I do that with a series?
Posted By: AndrewAMD

Re: Populating an array of dynamic size on each run of run() - 02/04/21 13:40

Allocations are slow.

The trick is to use a fixed-size buffer and only use as many elements as you need per run.

Incidentally, the maximum number of contracts available at any given run is MAX_CONTRACTS, so use MAX_CONTRACTS for your number of fixed buffer elements.
© 2024 lite-C Forums