I am considering writing an app that would create several hundred or
a few thousand copies of a single object. One way to keep track of them
is to use an array. A script that tests this syntax is below along with
a run which does a "print mold" on the array. It appears that the
functions(methods) in the object are replicated for each instance
of the object in the array. Is this true? Is this efficient? I am more
used to OO languages like C++ where only the data fields would
be replicated and there would be only one copy of the functions
for all the instances of the class. Is there a better way to do this? 





==== start of script 

REBOL [ Title: "test05 "
        Author: " ww "
      ]


print " demo "

count-x:  1

myobj:  [
             x: (count-x)
             y: 5
             myfun: func [ x ] [ return x ]
             myfun2: func [ ] [ return y ]
        ]


xarr: array 5

for i 1 5 1 [ do rejoin compose ["xarr/" (i) ": (make object! myobj  ) "  ]
               count-x: count-x + 1
             ]


print mold xarr

===== end of script

===== start of run

>> do %t05.r
Script: "test05 " (none)
 demo 
[
    make object! [
        x: 1
        y: 5
        myfun: func [x][return x]
myfun2: func [][return y]
] 
make object! [
x: 2
y: 5
myfun: func [x][return x]
myfun2: func [][return y]
] 
make object! [
x: 3
y: 5
myfun: func [x][return x]
myfun2: func [][return y]
] 
make object! [
x: 4
y: 5
myfun: func [x][return x]
myfun2: func [][return y]
] 
make object! [
x: 5
y: 5
myfun: func [x][return x]
myfun2: func [][return y]
]]

==== end of run

Reply via email to