Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
is there a maximum struct size? #396081
03/02/12 14:05
03/02/12 14:05
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
hi,

for my pathfinder I'm creating crazy struct arrays containing long arrays. in theory it should work, but I get script crash messages when the struct size go over 50 kbyte. (the limit is not 64 kb)

if the 1st three variables are var, then max 3000 element is working (48000b), but if short even 5000 is okay (50000b). the length "m" of the struct array has no effect on errors at all.

probably I'm wrong with memory allocation. it works now, but I would like to know the error reason, any help welcome. thanks. and of course separate arrays could be used too, I know, but it is more simple to use one parameter when calling functions.

Code:
typedef struct			// group A* struct
{
short f[5000];			// it was var but short works better -> and works with as high as 5000 elements too!!!
short g[5000];			// it was var but short works better
short h[5000];			// it was var but short works better
short parent_cluster[5000];
char clist[5000];		// BOOL 
char olist[5000];		// BOOL 
} PLAY02_CLUSTERASTARSYS;

PLAY02_CLUSTERASTARSYS* play02_group_astar = NULL;

...

play02_group_astar = (PLAY02_CLUSTERASTARSYS*)sys_malloc( (int)m * sizeof(PLAY02_CLUSTERASTARSYS) );	
memset( play02_group_astar , 0 , (int)m*sizeof(PLAY02_CLUSTERASTARSYS) );




Free world editor for 3D Gamestudio: MapBuilder Editor
Re: is there a maximum struct size? [Re: sivan] #396319
03/05/12 16:51
03/05/12 16:51
Joined: Dec 2009
Posts: 128
China
frankjiang Offline
Member
frankjiang  Offline
Member

Joined: Dec 2009
Posts: 128
China
you can use malloc to create object.

Code:
function foo()
{
  SPOT* myspot = malloc(sizeof(SPOT)); // creates a new SPOT struct at runtime
  memset(myspot,0,sizeof(SPOT)); // set the struct content to zero (it's undefined after malloc)
  myspot->x = 1;  
  SPOT* spot_array = malloc(100*sizeof(SPOT)); // creates an array of 100 SPOT structs
  memcpy(&spot_array[0],myspot,sizeof(SPOT));  // copy the myspot struct to the first member of the array
  ...
  free(myspot); // removes the created structs
  free(myspot_array);
}




development 3d game is interesting!
Re: is there a maximum struct size? [Re: frankjiang] #396342
03/05/12 20:39
03/05/12 20:39
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline OP
Expert
sivan  Offline OP
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
thanks, I used sys_malloc which is very similar. Jcl confirmed that there's no limit, and it is better not to use crazy structs containing arrays...


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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