2016-04-05 8 views
0

私はスキーマに一致するクラスを持っています。orderedディクテーションまたはディクテーションのサイズが構成要素より小さいか?

class EnvelopeData(object): 

    def __init__(self): 
    self.envelope_data = OrderedDict() 
    self.table = table_name 
    self.payload = payload 

    def get_envelope_data(self, use_hex_encoding): 
    """ 
     Getting the envelope data to be sent with the actual record payload 

     :param use_hex_encoding: 
     :raise: 
    """ 
    self.envelope_data["table"] = self.table.encode(STRING_ENCODING) 
    self.envelope_data["payload"] = Utility.get_serialized_avro(self.table, 
                  hex_encoding=use_hex_encoding) 

    print "For schema_name ", self.schema, sys.getsizeof(self.envelope_data["table"])+sys.getsizeof(self.envelope_data["payload"]) 

とも私は

a = EnvelopeData() 
a.get_envelope_data() 
print sys.getsizeof(a.envelope_data) 

内の要素の大きさ>要素が含まordereddictのサイズを印刷します。ですから、私は、辞書がどのようにしてその構成要素より小さな空間を取ることができるのか混乱しています。あなたがそれを見ることができますsys.getsizeof()ドキュメントによって

+0

辞書は、ほとんどのPythonデータ構造と同様、その中に含まれる要素に*参照*を保持します。 – jonrsharpe

答えて

2

、具体的に言う:直接オブジェクトに起因

だけのメモリ消費は、それが参照するオブジェクトのないメモリ消費量を占めています。

意味すると、辞書内の項目はサイズの一部としてカウントされず、辞書オブジェクト自体のみがカウントされます。
また、項目を辞書に含める再帰的なサイズrecipeにリンクします。

関連する問題