python - Accessing Dictionaries VS Accessing Shelves -


Currently, I have a dictionary in which the key is in the form of a number and a square in the form of a value I Class characteristics can be used like:

  dictionary [str (instantiated_class_id_number)] Attribute1  

Due to memory problems, I want to use the Plane module I think it is appropriate to do this. Does a Strong Dictionary work as accurate as a standard dictionary? If not, how is it different?

The Shelves do not work very similarly to the dictionary, especially when modified objects that are already Are in the dictionary only

The difference is that when you add a square to a dictionary, a reference is stored, but keeps a spicy (serialized) copy of the object. If you modify the object, you will modify the in-memory copy, but not the spicy version. It can be controlled by (mostly) transparent shelf.sync () and shelf.close () , which write entries. All work needs to be tracked for all the recovered items, which have not yet been rewritten, so you have to call shelf.sync () to clear the cache.

shelf.sync () Clearing the cache is that you can reference the object and modify it again.

This code does not work as expected from the shelf, but will work with a dictionary:

  s ["foo"] = MyClass () s ["foo" ]. X = 8 P = s ["foo"] # Object PX = 9 # Refer to the reference of the reference reference s.sync () #cachepx = 0 print "value in memory:% d"% px # print prints "in the shelf Value:% d "% s [" foo "]. X # print 9>  

The sync process processes the flash cache so that the modified 'P' object has been lost with the cache, so it has not been written back.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -