Object as an array or hash?

Discussion in 'Ruby' started by rolo, Jun 29, 2004.

  1. rolo

    rolo Guest

    Hi

    I am currently implementing a VM for Ruby. The code shall be compiled in my
    case.

    Currently, the instance variables are implemented as an hash table. In
    complied form it can be also implemented as an array.
    Both of the methods have its only drawbacks and advantages but no
    limitations on implementing the ruby language as it is currently.

    Has anyone thought about which might be better in case of compiled code?

    Thanks and Regards,

    rolo
     
    rolo, Jun 29, 2004
    #1
    1. Advertising

  2. "rolo" <> schrieb im Newsbeitrag
    news:...
    > Hi
    >
    > I am currently implementing a VM for Ruby. The code shall be compiled in

    my
    > case.


    Compiled to what? Java bytecode?

    Did you look at those projects under way dealing with Java bytecode
    compilation and native compilation?

    > Currently, the instance variables are implemented as an hash table. In
    > complied form it can be also implemented as an array.
    > Both of the methods have its only drawbacks and advantages but no
    > limitations on implementing the ruby language as it is currently.
    >
    > Has anyone thought about which might be better in case of compiled code?


    A hash since you don't know at compile time how many instance variables
    there will be. You can't know beforehand since there is
    #instance_variable_set and ...get.

    Regards

    robert
     
    Robert Klemme, Jun 29, 2004
    #2
    1. Advertising

  3. "rolo" <> wrote in message
    news:...
    > Hi
    >
    > I am currently implementing a VM for Ruby. The code shall be compiled in

    my
    > case.
    >


    What implementation language do you use ? (C++, Java, ...)
    What's the 'compiler output' ? (executable binary, bytecode, ...)

    > Currently, the instance variables are implemented as an hash table.


    How is the hash table implemented right now ?

    Is it implemented all by yourself, ...
    e.g: What 'type' is the hash-key of ? (string, object identifier, ...)
    Where is the 'data content' of the object instance stored in ?
    (statically/dynamically allocated memory)

    .... or is there some element / interface / library of your implementation
    language you can use ?

    > In complied form it can be also implemented as an array.
    > Both of the methods have its only drawbacks and advantages but no
    > limitations on implementing the ruby language as it is currently.
    >
    > Has anyone thought about which might be better in case of compiled code?


    What do you mean with 'better',
    or, at least, where are your preferences ?

    Data Reliability ?
    Performance ?
    Memory usage ?
    Flexibility in internal data structure ?

    A lot of questions, I know.
    But 'better' depends on them.

    Kind regards,
    Chris

    >
    > Thanks and Regards,
    >
    > rolo
    >
    >
    >
    >
     
    Christoph Neubauer, Jun 29, 2004
    #3
  4. At a local level, I would expect that a good hash table implementation
    will give the most consistent performance. However, you might be able
    to improve on it with an array or linked list for some operations, or
    in some inernal classes. If you really want to find out which is
    better, then implement both and compare the runtime performance. There
    are just too many variables in this case to know which will be faster
    overall.

    Hash tables, alists, red/black trees, splay trees, etc., all have
    different performance based on the number of keys to be compared, cost
    of key comparison, balance of read vs. write operations, etc. It's
    probably best to implement the clean, naive version (i.e., hash
    tables), and then tweak the performance from there.

    Lennon
     
    Lennon Day-Reynolds, Jun 29, 2004
    #4
  5. rolo

    rolo Guest


    > -----Original Message-----
    > From: Robert Klemme [mailto:]
    > "rolo" <> schrieb im Newsbeitrag
    > news:...
    > > Hi
    > >
    > > I am currently implementing a VM for Ruby. The code shall be compiled in

    > my
    > > case.

    >
    > Compiled to what? Java bytecode?


    Bytecodes. Vuby Bytecodes.
    >
    > Did you look at those projects under way dealing with Java bytecode
    > compilation and native compilation?
    >
    > > Currently, the instance variables are implemented as an hash table. In
    > > complied form it can be also implemented as an array.
    > > Both of the methods have its only drawbacks and advantages but no
    > > limitations on implementing the ruby language as it is currently.
    > >
    > > Has anyone thought about which might be better in case of compiled code?

    >
    > A hash since you don't know at compile time how many instance variables
    > there will be. You can't know beforehand since there is
    > #instance_variable_set and ...get.
    >

    Array might be good in terms that We can know at most of the places where
    access with directly. To the places where the access is runtime based, we
    can first lookup the index and the access it.

    rolo
     
    rolo, Jun 30, 2004
    #5
  6. rolo

    rolo Guest


    > -----Original Message-----
    > From: Christoph Neubauer [mailto:]
    >
    > "rolo" <> wrote in message
    > news:...
    > > Hi
    > >
    > > I am currently implementing a VM for Ruby. The code shall be compiled in

    > my
    > > case.
    > >

    >
    > What implementation language do you use ? (C++, Java, ...)
    > What's the 'compiler output' ? (executable binary, bytecode, ...)


    I am implementing Vuby in C++. Compiler output is bytecode.

    >
    > > Currently, the instance variables are implemented as an hash table.

    >
    > How is the hash table implemented right now ?
    >
    > Is it implemented all by yourself, ...
    > e.g: What 'type' is the hash-key of ? (string, object identifier, ...)
    > Where is the 'data content' of the object instance stored in ?
    > (statically/dynamically allocated memory)
    >
    > .... or is there some element / interface / library of your implementation
    > language you can use ?
    >
    > > In complied form it can be also implemented as an array.
    > > Both of the methods have its only drawbacks and advantages but no
    > > limitations on implementing the ruby language as it is currently.
    > >
    > > Has anyone thought about which might be better in case of compiled code?

    >
    > What do you mean with 'better',
    > or, at least, where are your preferences ?
    >
    > Data Reliability ?
    > Performance ?
    > Memory usage ?
    > Flexibility in internal data structure ?
    >
    > A lot of questions, I know.
    > But 'better' depends on them.
    >

    Each of his paramaters have conflicts like Memory is less in Array kind
    rather than Hash but Array kind requires a recompile (internally for JIT
    compilation) instead of Hash.
    Better is that which suits 'general' conditions the best.

    regards,
    rolo
     
    rolo, Jun 30, 2004
    #6
  7. I totally agree to Lennon's statements below.
    ......
    And dont' forget the Garbage Collection !

    Kind regard,
    Chris

    "Lennon Day-Reynolds" <> wrote in message
    news:...
    > At a local level, I would expect that a good hash table implementation
    > will give the most consistent performance. However, you might be able
    > to improve on it with an array or linked list for some operations, or
    > in some inernal classes. If you really want to find out which is
    > better, then implement both and compare the runtime performance. There
    > are just too many variables in this case to know which will be faster
    > overall.
    >
    > Hash tables, alists, red/black trees, splay trees, etc., all have
    > different performance based on the number of keys to be compared, cost
    > of key comparison, balance of read vs. write operations, etc. It's
    > probably best to implement the clean, naive version (i.e., hash
    > tables), and then tweak the performance from there.
    >
    > Lennon
    >
    >
     
    Christoph Neubauer, Jul 1, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    594
    red floyd
    Nov 10, 2011
  2. Anthony Martinez
    Replies:
    4
    Views:
    300
    Robert Klemme
    Jun 11, 2007
  3. Michal Suchanek
    Replies:
    6
    Views:
    257
    Nobuyoshi Nakada
    Jun 13, 2007
  4. Pokkai Dokkai
    Replies:
    8
    Views:
    149
    Phrogz
    Nov 18, 2007
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    674
    David A. Black
    Jul 2, 2008
Loading...

Share This Page