shelve file space always increase!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • smalltalk

    #1

    shelve file space always increase!

    >>import shelve
    >>sf = shelve.open('e:/abc.db')
    >>for i in range(10000):
    .... sf[str(i)]=i
    ....
    >>sf.close()
    >>sf = shelve.open('e:/abc.db')
    >>sf.clear()
    >>sf
    {}
    the abc.db is always 312k though i have use clear(), how can i shrink
    the space?
  • skip@pobox.com

    #2
    Re: shelve file space always increase!


    smalltalkthe abc.db is always 312k though i have use clear(), how can
    smalltalki shrink the space?

    You really can't without deleting the file. Hash file implementations trade
    off file size against improve key lookup performance. Similar tradeoffs are
    made in the implementation of Python's dictionary and other languages'
    associative arrays.

    My Google skills must be lacking this morning. Here's the best I've been
    able to come up with in the way of explanation:



    Skip

    Comment

    • Michael Palmer

      #3
      Re: shelve file space always increase!

      On Sep 17, 6:17 am, smalltalk <ttkk1...@gmail .comwrote:
      >import shelve
      >sf = shelve.open('e:/abc.db')
      >for i in range(10000):
      >
      ... sf[str(i)]=i
      ...>>sf.close()
      >sf = shelve.open('e:/abc.db')
      >sf.clear()
      >sf
      >
      {}
      the abc.db is always 312k though i have use clear(), how can i shrink
      the space?
      shelve doesn't have any way of doing that. the only option is to read
      all items from your shelve and write them to a new one.

      Comment

      Working...