Welcome, Guest. Please login or register.
Did you miss your activation email?
September 09, 2010, 11:38 am
Home | Help | Search | Calendar | Login | Register

Valhalla Legends Forum  |  Programming  |  Web Development (Moderators: Invert, Arta)  |  Topic: PHP, Arrays, and memory
« previous next »
Pages: [1] Print
Author Topic: PHP, Arrays, and memory  (Read 77 times)
Arictos
Freedman
*
Offline

Posts: 13


Truth.

View Profile WWW
« on: July 14, 2010, 03:31 am »

So i'm working on a freelance combat-simulator for a clients game.  The basic structure of it, is that every unit has particular attributes, and fights to the death with the other team.  The attributes units have are:

Code: [Select]
$units = Array(
'Footman' => Array(
'health' => 420,
'armor' => 0.08,
'attack' => 17,
'range' => 5,
'dodge' => 0.2,
'crit' => 25.6
),
'Archer' => Array(
'health' => 505,
'armor' => 0,
'attack' => 28.5,
'range' => 10,
'dodge' => 0.5,
'crit' => 40.3,
),
'Catapult' => Array(
'health' => 700,
'armor' => 0.08,
'attack' => 68,
'range' => 20,
'dodge' => 0,
'crit' => 2.5,
),
);

So after a user defines how many of each type of unit they want, I loop through and create individual values for every unit in another array.  That way, when combat is simulated, every unit keeps attacking until the defending unit dies (or vice-versa) and then moves onto the next.

Now everything works great, up until I start entering in higher values, such as 50-100k units, then I recieve a lovely error message:

Code: [Select]
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 41 bytes) in ...
I'm aware of WHY i'm getting this message, but I need to figure out another way of doing things.  If I haven't made it clear as to how i'm handling everything now, please feel free to ask.  But it's something i'm not exactly sure as to what to do.  That, or you can see the development of it at http://arictos.com/_development/public_html which i'll have it showing "live" combat logs as the combat is done, with somewhere like 500 units.

Ideas?
« Last Edit: July 14, 2010, 04:53 am by Arictos » Logged
rabbit
Hearthman
****
Offline

Posts: 1385


RAWR!

View Profile
« Reply #1 on: July 14, 2010, 05:25 am »

Look into memcache (I'd post more but I'm going to get ready for work now).
Logged
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.
Pages: [1] Print 
Valhalla Legends Forum  |  Programming  |  Web Development (Moderators: Invert, Arta)  |  Topic: PHP, Arrays, and memory « previous next »
 


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.237 seconds with 15 queries.