Hi,
In message "Re: Segmentation Fault - Ruby Garbage Collection"
on 02/08/02, William Djaja Tjokroaminata <billtj / y.glue.umd.edu> writes:
|Probably the most direct problem that I am currently facing is, I will
|have many entities that will be created and destroyed so often (millions
|of times) such as packets and events. If the user is not going to have
|access to these entities, I can create efficient structures for them (even
|probably manage the memory usage.) However, when a user is allowed to
|interact with them, I am forced to make the packets and events as Ruby
|objects (to be honest, I don't know how much overhead the Ruby objects
|have as compared to straight C structs; I have not made comparison yet.)
5 words (20 bytes on int32 platforms) for each objects.
|I am thinking whether it is possible to design some "lazy evaluation" type
|of object. In other words, when the user does not interact with them,
|they are straight C structs so that the code is highly efficient. Once a
|user interact with an entity, however, the struct creates a Ruby object
|for the user to interface.
I now understand what you want. But I'm not sure if it's possible.
Probably the solution is wrapping your set of C data as a "lazy
evaluating" Ruby object which wraps your flyweight C data only when
the user starts interact with them.
|Another (simpler) example is when I want to reuse Ruby array in C, it
|forces all the entities to be Ruby objects, because a Ruby array, I think,
|cannot hold objects other than Ruby objects. So if I just want to have a
|(dynamic) array of double's, I am forced to create objects of type
|rb_cFloat instead of straight C double's. (Of course, in this case the
|solution is to use other C libraries.)
NumArray? See RAA.
matz.