use class variables instead of globals

and set page size from new argument
This closes #23 , though ripples will follow
This commit is contained in:
Torsten Ruger 2019-02-08 23:03:08 +02:00
parent d777b4fa88
commit 74b790250a
2 changed files with 12 additions and 8 deletions

View File

@ -15,8 +15,9 @@ module Parfait
class Factory < Object class Factory < Object
attr :type , :for_type , :next_object , :reserve , :attribute_name attr :type , :for_type , :next_object , :reserve , :attribute_name
PAGE_SIZE = 1024 @page_size = 1024
RESERVE = 10 @reserve_size = 10
class << self; attr_accessor :page_size ; attr :reserve_size end
# initialize for a given type (for_type). The attribute that is used to create the # initialize for a given type (for_type). The attribute that is used to create the
# list is the first that starts with next_ . "next" itself would have been nice and general # list is the first that starts with next_ . "next" itself would have been nice and general
@ -52,7 +53,7 @@ module Parfait
def get_more def get_more
first_object = get_chain first_object = get_chain
link = first_object link = first_object
count = RESERVE count = Factory.reserve_size
while(count > 0) while(count > 0)
link = get_next_for(link) link = get_next_for(link)
count -= 1 count -= 1
@ -67,9 +68,9 @@ module Parfait
# it creates objects from the mem and link them into a chain # it creates objects from the mem and link them into a chain
def get_chain def get_chain
raise "type is nil" unless self.for_type raise "type is nil" unless self.for_type
first = sys_mem( for_type , PAGE_SIZE) first = sys_mem( for_type , Factory.page_size)
chain = first chain = first
counter = PAGE_SIZE counter = Factory.page_size
while( counter > 0) while( counter > 0)
nekst = get_next_raw( chain ) nekst = get_next_raw( chain )
set_next_for(chain, nekst) set_next_for(chain, nekst)
@ -102,7 +103,7 @@ module Parfait
# return more memory from the system. # return more memory from the system.
# Or to be more precise (as that is not really possible), allocate memory # Or to be more precise (as that is not really possible), allocate memory
# for PAGE_SIZE objects, and return the first object. # for Factory.page_size objects, and return the first object.
# ( the object has a type as first member, that type will be the for_type of this factory) # ( the object has a type as first member, that type will be the for_type of this factory)
# This implementation will be moved to the adapter, as the real thing needs to be coded # This implementation will be moved to the adapter, as the real thing needs to be coded
# in risc # in risc

View File

@ -49,13 +49,16 @@ module Parfait
# - create the Class objects and assign them to the types # - create the Class objects and assign them to the types
# - flesh out the types , create the real space # - flesh out the types , create the real space
# - and finally load the methods # - and finally load the methods
def self.boot! def self.boot!(options)
Parfait.set_object_space( nil ) Parfait.set_object_space( nil )
types = boot_types types = boot_types
boot_boot_space( types ) boot_boot_space( types )
classes = boot_classes( types ) classes = boot_classes( types )
fix_types( types , classes ) fix_types( types , classes )
if( page = options[:page_size])
Factory.page_size = page
PUTS "PAGE #{page}"
end
space = Space.new( classes ) space = Space.new( classes )
Parfait.set_object_space( space ) Parfait.set_object_space( space )
end end