Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Object as an array or hash?

Reply
Thread Tools

Object as an array or hash?

 
 
rolo
Guest
Posts: n/a
 
      06-29-2004
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




 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      06-29-2004

"rolo" <(E-Mail Removed)> schrieb im Newsbeitrag
news:ACEPLIKLBKEMDDIELPKIKEIACIAA.rohitlodha@hotwi reindia.com...
> 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

 
Reply With Quote
 
 
 
 
Christoph Neubauer
Guest
Posts: n/a
 
      06-29-2004

"rolo" <(E-Mail Removed)> wrote in message
news:ACEPLIKLBKEMDDIELPKIKEIACIAA.rohitlodha@hotwi reindia.com...
> 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
>
>
>
>



 
Reply With Quote
 
Lennon Day-Reynolds
Guest
Posts: n/a
 
      06-29-2004
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


 
Reply With Quote
 
rolo
Guest
Posts: n/a
 
      06-30-2004


> -----Original Message-----
> From: Robert Klemme [(E-Mail Removed)]
> "rolo" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:ACEPLIKLBKEMDDIELPKIKEIACIAA.rohitlodha@hotwi reindia.com...
> > 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




 
Reply With Quote
 
rolo
Guest
Posts: n/a
 
      06-30-2004


> -----Original Message-----
> From: Christoph Neubauer [(E-Mail Removed)]
>
> "rolo" <(E-Mail Removed)> wrote in message
> news:ACEPLIKLBKEMDDIELPKIKEIACIAA.rohitlodha@hotwi reindia.com...
> > 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




 
Reply With Quote
 
Christoph Neubauer
Guest
Posts: n/a
 
      07-01-2004
I totally agree to Lennon's statements below.
......
And dont' forget the Garbage Collection !

Kind regard,
Chris

"Lennon Day-Reynolds" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM
Passing derived class object array in place of base class object array justanotherguy63@yahoo.com C++ 9 12-03-2004 10:57 PM
Problem assigning an Array object to an Array-subclass object Richard Lionheart Ruby 27 05-04-2004 06:42 AM



Advertisments