[Solved] Struct Limits... Again

Started by KamikazeHighland, Fri 06/01/2012 06:36:38

Previous topic - Next topic

KamikazeHighland

There've been a few topics on this, but I'd like any new information anyone might have.  This is the code that works fine:

struct Example {
 int PropertyAofSubstruct[256];
 int PropertyBofSubstruct[256];
 int PropertyCofSubstruct[256];
 float Property1ofSubstruct[2560];
 float Property2ofSubstruct[2560];
 float Property3ofSubstruct[2560];
 float Property4ofSubstruct[2560];
 float Property5ofSubstruct[2560];
 float Property6ofSubstruct[2560];
 float Property7ofSubstruct[2560];
 int PropertyDofSubstruct[256];
 int PropertyEofSubstruct[256];
 int PropertyFofSubstruct[256];
 float Property8ofSubstruct[2560];
 float Property9ofSubstruct[2560];
 float Property10ofSubstruct[2560];
 float Property11ofSubstruct[2560];
 float Property12ofSubstruct[2560];
 float Property13ofSubstruct[2560];
 float Property14ofSubstruct[2560];
 int PropertyA[256];
 int PropertyB[256];
 float PropertyI;
 float PropertyII;
 float PropertyIII;
 };
Example examples[256];

If I make either of two changes:

Replacing each [256] with [2560] or replacing the number of instances of the struct:
Example examples[2560];

I get this, which many have probably encountered:
Error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Version: AGS 3.2.1.111

Or if I have just enough room I can store a few floats before the running program crashes saying the error is in the line it stopped writing.

The only reason I started a new thread is because it's been said there should be no limit so I'm a little confused on that.  I was able to bump the limits up once I deleted some pictures.  I realize I could settle for less but what's the problem?

Gilbert

I think while there isn't any logical limit there should obviously be some physical limits.

I'm not sure about these limits, but they're either hard-coded in the engine on at most how much memory can be allocated and/or limited by the system.

In your example, each instance of the struct contains 256*8 + 2560*14 + 3 = 37891 variables.  I'm too lazy to check how many bytes each kind of variables would use but let's assume int and float are 4 bytes each (this would only be an underestimate, never an overestimate), then each instance takes 4*37891 = 151564 bytes, which is about 150KB already.

When you declare Example examples[256] you need  151564*256 = 38800384 bytes (plus overheads). This almost takes 40MB already.

So, if you declare Example examples[2560] this array alone would eat up about 400MB of memory, which is insane.

Note also that even if your own test system can pull that off that doesn't mean the majority of players' systems can, so it's not recommended to use huge amount of memory on your variables. After all, AGS was not designed for making graphic processing programmes or spreadsheets to begin with.

KamikazeHighland

Well I'll probably just abandon structs for now and do everything as dynamic arrays, or remove information from memory more quickly.  The struct alone takes up 40mb so obviously even three would take up 120mb...

Thanks for the reply!

SMF spam blocked by CleanTalk