Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Memory usage in Python?

I have posted a topic a while back that asked about the best way to save items in Python. So far, I believe that I will use the "visited" approach, meaning every time the player leaves or enters a map, several things will happen.1: The player enters and the name of the map will be checked against an internal dictionary containing map item and possibly NPC states. If the name is found, then the map item and NPC lists will be overwritten. If the name is not found, the game will read the map files to determine map state.2: The player leaves and the same process is performed, except if the name is found, the two lists will be checked for equality and overwritten only if the current one is newer than the one located in the dictionary. If the name is not found, then the map name and it's info will be added to the ever-growing information.3: Whenever the player saves, the dictionary of map info will be exported with the file.This all sounds good on paper, but I'm not sure of how practical this would be. I'm planning to pickle the lists and encrypt them when I save and to do the opposite when loading the information back into the game. Can anyone point out any flaws they see with this approach and how would you go about fixing those flaws? My worry is the eventual memory size of the information. I have not managed to find any information on the maximum memory available in Python and that's why I'm asking here.

URL: https://forum.audiogames.net/post/459619/#p459619




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Memory usage in Python?

I have posted a topic a while back that asked about the best way to save items in Python. So far, I believe that I will use the "visited" approach, meaning every time the player leaves or enters a map, several things will happen.1: The player enters and the name of the map will be checked against an internal dictionary containing map item and possibly NPC states. If the name is found, then the map item and NPC lists will be overwritten. If the name is not found, the game will read the map files to determine map state.2: The player leaves and the same process is performed, except if the name is found, the two lists will be checked for equality and overwritten only if the current one is newer than the one located in the dictionary. If the name is not found, then the map name and it's info will be added to the ever-growing information.3: Whenever the player saves, the dictionary of map info will be exported with the file.This all sounds good on paper, but I'm not sure of how practical this would be. I'm planning to pickle the lists and encrypt them when I save and to do the opposite when loading the information back into the game. Can anyone point out any flaws they see with this approach and how would you go about fixing those flaws? My worry is the eventual memory size of the dictionary. I have not managed to find any information on the maximum memory available in Python and that's why I'm asking this on here.

URL: https://forum.audiogames.net/post/459619/#p459619




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector


  


Re: Memory usage in Python?

First, the maximum memory usage of Python is just the same as for any other process running under operating systems, means 3,2 GB when x86 and alot more when x64. I however don't believe that your dictionary will grow that large. Why don't you store NPCs and whatever inside a map class and hold a list of map objects instead of a dictionary? You can implement comparison operators for map objects to find out if a map with that name already exists and if it is already up-to-date or if it needs to be updated. You could even add an update() method to that object to perform the necessary update steps to be up-to-date again by populating the new values.Its not like your attempt is bad, it will work pretty well I guess, it just sounds like it could be more dynamic and powerful when thinking in OOP-style.Best Regards.Hijacker

URL: https://forum.audiogames.net/post/459631/#p459631




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Memory usage in Python?

I haven’t considered that, mostly because I did not ever try to override default operators.

URL: https://forum.audiogames.net/post/459644/#p459644




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Memory usage in Python?

I haven’t considered that, mostly because I did not ever try to override default operators. I also am not totally sure what do you mean by saying comparison method that checks for map names.  I was just going to create a function that  loops through the list and tries to find a match by checking all the names.

URL: https://forum.audiogames.net/post/459644/#p459644




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Memory usage in Python?

I haven’t considered that, mostly because I did not ever try to override default operators. I also am not totally sure what do you mean by saying comparison method that checks for map names.  I was just going to create a function that  loops through the list and tries to find a match by checking all the map names. Sorry for the bad grammar, currently in a bit of a hurry.

URL: https://forum.audiogames.net/post/459644/#p459644




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector


  


Re: Memory usage in Python?

Hi,yeah, that is a way, but overloading the map operator would be more efficient. By doing that and accepting a string as comparable, checking if the string equals the map name, you can use the built-in methods of python lists to find the map you're looking for, like:def find_map(name):
  idx = my_map_list.index(name)
  if idx >= 0:
return my_map_list[idx]
  return NoneTo write a function that finds a certain map, without worrying about the way to walk through those lists yourself.Just an idea. You can do pretty performant and nice-looking things by simply overloading operators, in whatever language.Best Regards.Hijacker

URL: https://forum.audiogames.net/post/459659/#p459659




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Memory usage in Python?

Alternatively, python provide a set of methods in classes called dunder methods. Those methods allow you to override operators of your classes. In this case, you'd want to override the equals operator and do something like the following:class map:    def __init__(self, name):        self.name = name    # __eq__ is used to override the equals operator    def __eq__(self, other):        return self.name == other.name or self.name == nameBy doing this you can directly compare a map with an other map, or a string object with the map. So instead of doing m.name == name you could do m == name

URL: https://forum.audiogames.net/post/459661/#p459661




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Memory usage in Python?

Alternatively, python provide a set of methods in classes called dunder methods. Those methods allow you to override operators of your classes. In this case, you'd want to override the equals operator and do something like the following:class map:    def __init__(self, name):        self.name = name    # __eq__ is used to override the equals operator    def __eq__(self, other):        return self.name == other.name or self.name == otherBy doing this you can directly compare a map with an other map, or a string object with the map. So instead of doing m.name == name you could do m == name

URL: https://forum.audiogames.net/post/459661/#p459661




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector


  


Re: Memory usage in Python?

Thats exactly what I was recommending, I just wanted him to search a bit for himself . I however would consider backing that operator up with some type checking, or at least exception checking (just following the etafftp pattern), cause otherwise the whole thing would crash down in flames if you throw something in there that doesn't have a name attribute, and since you put the self.name == other.name evaluation first, it will even crash when comparing to strings. I'd consider something like that in Python 3:  def __eq__(self, other):
if isinstance(other, str):
  return self.name == other
elif isinstance(other, map):
  return self.name == other.name
return NotImplementedBest Regards.Hijacker

URL: https://forum.audiogames.net/post/459662/#p459662




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : Hijacker via Audiogames-reflector


  


Re: Memory usage in Python?

Thats exactly what I was recommending, I just wanted him to search a bit for himself . I however would consider backing that operator up with some type checking, or at least exception checking (just following the etafftp pattern), cause otherwise the whole thing would crash down in flames if you throw something in there that doesn't have a name attribute, and since you put the self.name == other.name evaluation first, it will even crash when comparing to strings. I'd consider something like that in Python 3:  def __eq__(self, other):
if isinstance(other, str):
  return self.name == other
elif isinstance(other, map):
  return self.name == other.name
return NotImplementedOr like the following (if you like to follow etafftp):  def __eq__(self, other):
try:
  return self.name == other.name
except AttributeError:
  return self.name == otherYou'd still need to either do more checking that way, or you could throw almost anything in there and it will simply compare it to your map name and see if it matches .Best Regards.Hijacker

URL: https://forum.audiogames.net/post/459662/#p459662




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Memory usage in Python?

Yeah, I actually hsould have, and due to time I rushed sorry for that .

URL: https://forum.audiogames.net/post/459679/#p459679




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-04 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Memory usage in Python?

Thank you you two.  The example confirmed what I have found when searching, and  I did not think about the possible error, So you have saved me a bit of a headache.

URL: https://forum.audiogames.net/post/459681/#p459681




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-05 Thread AudioGames . net Forum — Developers room : NicklasMCHD via Audiogames-reflector


  


Re: Memory usage in Python?

Hi.@amerikranian what you also want to take into consideration is that you don't load everything in at once (if the map is large enough, it could crash your game).Another thing, I also would recomend is not to pickle it but use json or something similar, due to possible security concerns with pickle."Warning: The pickle module is not secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source." source: https://docs.python.org/3/library/pickle.htmlHope that helps.

URL: https://forum.audiogames.net/post/459771/#p459771




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Memory usage in Python?

2019-09-05 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Memory usage in Python?

Pickle won't be the only thing I used when exporting. I am aware of the possible security issues. Thanks for the tip, though.What do you mean by "loading too large of a map?" As far as I know, memory limit is the only thing I should be concerned about. My map is not a 2d array, either.

URL: https://forum.audiogames.net/post/459785/#p459785




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector