Object as an array or hash?

R

rolo

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
 
R

Robert Klemme

rolo said:
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
 
C

Christoph Neubauer

rolo said:
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
 
L

Lennon Day-Reynolds

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
 
R

rolo

-----Original Message-----
From: Robert Klemme [mailto:[email protected]]
rolo said:
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?


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
 
R

rolo

-----Original Message-----
From: Christoph Neubauer [mailto:[email protected]]

rolo said:
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.
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 ?


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
 
C

Christoph Neubauer

I totally agree to Lennon's statements below.
......
And dont' forget the Garbage Collection !

Kind regard,
Chris
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top