Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by 7th_zorro. 04/16/24 13:19
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
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Aku_Aku, VoroneTZ, 11honza11), 376 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dynamic array crashes zorro #472341
04/22/18 06:11
04/22/18 06:11
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
I finally managed to implement a dynamic array. Pretty simple and straightforward, but Zorro keeps crashing randomly. Here is a demo code:

Code:
typedef struct {
	var variable1;
	var variable2;
	var variable3;
	var variable4;
	int variable5;
	int variable6;
	var variable7;
	var variable8;
	int variable9;
} MYSTRUCT;	
	


static int arraysize;

int i;	
	
int main()
{
MYSTRUCT *dynarray, *temp;
arraysize = 8; //start small
dynarray = malloc(arraysize*sizeof(MYSTRUCT));
//int increment = 20;

	for (i = 1; i < 65536; i++){
		
		
		
		if(i >= arraysize)
		{
			temp = realloc(dynarray,(arraysize*2)*sizeof(MYSTRUCT)); /* double array size */
			arraysize = arraysize*2;
			printf("nsize of array increased to %d elements!", arraysize);
			if ( temp != NULL )
			{
				dynarray = temp;
			}
				else			
			{
				free(dynarray);
				printf("nError allocating memory! Support and Resistance Indicatorn");
				printf("nFatal Error!!!");
			}
		}
		
		dynarray[i].variable5 = i; //save some value
		printf("ni = %d; dynarray[1]variable5 = %d; arraysize = %d", i, dynarray[i].variable5, arraysize);
	}
	
	for (i = 0; i < arraysize; i++) printf("n%d", dynarray[i].variable5);
	
	free(dynarray);
}



I need the struct for my project and just randomly picked one of the int variables (variable5) to demonstrate that the array actually is functioning.

What I don't understand is that I never get the Error message. Zorro just crashes by not responding anymore.

I'm thankful for any suggestions to make this work!

Re: Dynamic array crashes zorro [Re: Smon] #472342
04/22/18 06:14
04/22/18 06:14
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
The issue seems not related to the realloc function. If I start with

Code:
arraysize = 65536;



it keeps crashing anyway.

Last edited by sdh309795gaas; 04/22/18 06:14.
Re: Dynamic array crashes zorro [Re: Smon] #472346
04/22/18 11:09
04/22/18 11:09
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
Spain
I haven't had any succeed with dynamic arrays in Zorro either. They are tricky in standard C, so who knows what happens inside Lite-C...

Better off using an oversized static array or a series.

Re: Dynamic array crashes zorro [Re: Brax] #472348
04/22/18 15:11
04/22/18 15:11
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
My concern is, that a static array of some thousand elements will crash Zorro as well, and I need one of these arrays for each of the 27 currency pairs. Looks like the only option is using R...?

Last edited by sdh309795gaas; 04/22/18 15:13.
Re: Dynamic array crashes zorro [Re: Smon] #472349
04/22/18 15:22
04/22/18 15:22
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
a large static array with 1000 elements of the type MYSTRUCT works, but 1500 elements is already too much and produces Error 111...

So I'm better off with the dynamic array.... cry

Re: Dynamic array crashes zorro [Re: Smon] #472362
04/23/18 09:31
04/23/18 09:31
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
Spain
Well, maybe it's an internal limitation... jcl should know that.

If you don't really need to keep all the data at the same time, you could use a series and shift it whenever you want.

http://www.zorro-trader.com/manual/en/series.htm

Hope it helps.

Re: Dynamic array crashes zorro [Re: Brax] #472369
04/23/18 12:55
04/23/18 12:55
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
I already thought about that, but I really do need everything in memory. Thx!

Re: Dynamic array crashes zorro [Re: Smon] #472371
04/23/18 14:08
04/23/18 14:08
Joined: Dec 2014
Posts: 206
Germany
Smon Offline OP
Member
Smon  Offline OP
Member

Joined: Dec 2014
Posts: 206
Germany
It turns out that the printf loop is the culprit. Zorro obviously has a problem when you print out too much stuff to the console....!


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