Staredit Network > Forums > Technology & Computers > Topic: Help me program
Help me program
Dec 12 2010, 6:29 am
By: Sand Wraith  

Dec 12 2010, 6:29 am Sand Wraith Post #1

she/her

If ever I said I was any good at programming, consider the statement null and void.

I need some help with Python (3.x; 3.1.2 specifically) - using Windows 7 (and, thanks to the modules I'm using, it's only compatible with Windows).

Between style, syntax, and algorithms, my code is usually pretty horrendous. These factors do not help at all, especially for my current program.

ATM, I'm trying to program a simulator (for a zombie apocalypse? I dunno). All I've got are a map, some functions for running each turn, some functions for adding shit, terrain, and units.

My biggest problem right now is memory handling and efficiency. My units are implemented as such: their is a base unit class, and I have several (hundreds, sometimes) objects of the unit class. The class has functions for moving the units, which follow a convoluted and ridiculous pathing algorithm to determine where to move next.

I have a feeling that somewhere along the way of all of this, I'm leaking a massive fuckton of memory. My reasoning? I'm running a Windows 7 64-bit, i7-720 Quad Core, 9GB DDR3 machine and after just a few thousand turns (or something) with a few hundred people walking around, my computer gets whacked. I only noticed this just now: while I was running a test (probably a hundredth test or so), reaching into some 3000 turns with a few hundred persons on the field, my entire desktop flickered and changed to the default Windows 7 style. It only changed back after I went into the task manager and stopped multiple (several tens, at least) instances of "python.exe", each one taking some 17,000K of memory (or something).

In any case, I'd like to get some help with cleaning up my code, since, frankly, I'm too inexperienced to cut down on memory costs and leaks and shit.

The *.py files should be in the same folder. Use Python 3.x (I dunno if the specific version number will matter much; I'm using 3.1.2). Use Windows to test.
I've been testing for syntax/run-time errors using IDLE in interactive mode, writing the actual code in IDLE script mode, and also quick-testing by running the script by double-clicking "i dunno 2.py" (hurrdurr).
I've also had the "iD_mapLegend.py" file open simultanesouly.

Hope the info helps. I hope you can help (although my code is pretty terrible; I don't blame you if you tell me to clean up my style and such :P ).

http://pastebin.com/kqdVmTSY - main, "i dunno 2.py"
http://pastebin.com/dcJWUH4p - module, "iD_mapLegend.py"

Post has been edited 1 time(s), last time on Dec 12 2010, 7:49 pm by Sand Wraith.




Dec 12 2010, 7:35 pm CecilSunkure Post #2



Python should have a built in garbage collection system to prevent memory leaks. Since Python is a high level programming language, you don't get to mess with anything low-level and don't need to worry about cleaning up your memory allocation. I haven't looked at your code, but it's something else that is causing problems.



None.

Dec 13 2010, 7:52 am ShadowFlare Post #3



It is probably whatever is causing it to run more python processes. Are you running any external scripts in your code? Not just including them, but actually running it as a separate process.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[07:32 pm]
Zoan -- I got $2000 bonus. I would like 2000 minerals, please
[04:15 am]
DarkenedFantasies -- you eat lots of beans
[03:46 am]
IskatuMesk -- how do i get gas
[2026-4-15. : 11:43 pm]
Moose -- you don't
[2026-4-15. : 10:06 pm]
Zoan -- how do i get minerals
[2026-4-14. : 11:45 pm]
ClansAreForGays -- Anyone wanna played Skewed StarCraft?
[2026-4-14. : 12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
[2026-4-13. : 10:07 pm]
NudeRaider -- ya why phone people when you can just write letters
[2026-4-13. : 9:37 pm]
IskatuMesk -- I have never and will never own a phone
[2026-4-13. : 9:15 pm]
NudeRaider -- Vrael ranting still is though
Please log in to shout.


Members Online: Zoan, Prankenstein