C
Charles Hixson
I want to have a class which occasionally updates a file, but I want to
ensure that it always flushes it's data to the file before the program
quits.
The class is called Words
What's the best approach to take here? I could just continually run a
flush cycle, but that seems an awful waste of resources, I'd rather
batch the updates, and only flush occasionally.
class Words
def initialize ()
@@words = Hash.new
@@words.default = nil
@@wtable = WordTable.instance #<<<=================
@@maxWord = @@wtable.maxWord
end # initialize
....
end # Words
WordTable is a singleton class, and it's the one that does the actual
writing, but it needs to get the data to do the updates from Words.
I'm considering:
def initialize ()
...
ObjectSpace.define_finalizer(@@words, proc { flush })
But I don't know how to evaluate whether it's a good idea or not...or
even how to tell afterwards (presuming it doesn't throw a "compile-time"
error).
ensure that it always flushes it's data to the file before the program
quits.
The class is called Words
What's the best approach to take here? I could just continually run a
flush cycle, but that seems an awful waste of resources, I'd rather
batch the updates, and only flush occasionally.
class Words
def initialize ()
@@words = Hash.new
@@words.default = nil
@@wtable = WordTable.instance #<<<=================
@@maxWord = @@wtable.maxWord
end # initialize
....
end # Words
WordTable is a singleton class, and it's the one that does the actual
writing, but it needs to get the data to do the updates from Words.
I'm considering:
def initialize ()
...
ObjectSpace.define_finalizer(@@words, proc { flush })
But I don't know how to evaluate whether it's a good idea or not...or
even how to tell afterwards (presuming it doesn't throw a "compile-time"
error).