Memory allocation

Batista, Facundo FBatista at uniFON.com.ar
Mon Sep 22 14:46:41 EDT 2003


#- Can you provide more background on the specific problem you need
#- to solve, or are you looking for a very general solution?  In 
#- other words, do you just need to know how much memory a list, or
#- an integer uses up, or do you think you need a general-purpose
#- function which works with any object of any type.

It's a very general question for a very particular problem, :)

My particular problem is that I want to store in memory a pickled object,
and then want to know if that object changed.

For example (code untested):

class ObjectControl:
	""" Class to control if an object changed. """
	def __init__(self, object):
		objectPickled = cPickle.dumps(object)
		return

	def objectChanged(self, newObject):
		newObjectPickled = cPickle.dumps(newObject)
		if newObjectPickled == self.objectPickled:
			return False
		else:
			return True

so....

object1 = pickle.load(myfile)
control1 = ObjectControl(object1)
...
#lot of stuff that could change my object
...
#write to disk only if necessary
if control1.objectChanged(object1):
	pickle.dump(myfile, object1)


Don't know if there's a better solution for this particular problem
(suggestions welcomed), but it still remains a general question: the other
day I wanted to know "how much more expensive in memory is a list than a
tuple for a given content".

Get my idea?

Thanks for all!

.	Facundo





More information about the Python-list mailing list