Am Sonntag 07 Dezember 2003 21:33 schrieb Konstantin Knizhnik:
> Hello Volker,
>
> The problem is that I want to be able to store in database ANY object.
> So, if I correctly understand you, the only possible solution in this
> case is create string with definition of the object "make object! ..."
> and then evaluate this string using "do".
> It seems to me that performance of such solution will be awful.
>
> Ok, then alternative is to require persistent object to contain "class:"
> attribute which specifies prototype object. In this case I database do not
> need to store/load methods. It will use prototype object for creation of
> loaded instances. And one more question: I find out no way to locate object
> by string except using "do". Is it the only possible solution and how
> expensive it is? If it is really the only possible way to
> locate the object by name and it is not very fast, then I will use
> hash table to keep name->object mapping.

You mean to find the prototype-object? do a-word should be very fast.
a word is kind if string hashed by the global context.
about [to-word string] i am not sure, but should be fast. because it is
done all the time by 'load, so optimized.

But hashs are very fast to. so i am interested in a benchmark :)
Also with hashes you have more control about naming of prototypes.
Otherwise if your code does not contain a prototype, but accidentally
a function with the prototype-name exists, [do to-word string] is a bad idea.
there is a way to put all proto-objects in a context, like
  protos: context[proto1: ...]
  do in protos to-string word
[in protos something] returns none if the word does not exist IIRC.
But a hash is as good a solution.

for benchmarking:

  findme: context[]
  t1: now/precise
  loop 1'000'000[ do to word! "findme" ]
  difference now/precise t1
== 0:00:05.166109
(with (to-word instead) of[to word!] == 0:00:06.617021)

  protos: to-hash reduce["findme" context[]]
  t1: now/precise
  loop 1'000'000[ select protos "findme" ]
  difference now/precise t1
== 0:00:04.995347

on p350. Hash wins, but very close.

>
> Thanks in advance
> Konstantin
>

HTH :)
-Volker

-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to