“Jim Weirich” jweirich@one.net wrote in message
news:1053406677.17559.8.camel@traken…
How about this syntax …
auto(foo=MyObject.new, :cleanup) do
# use foo
end
fine if you can handle multiple objects this way. Mauricios suggestion does
that, but does not allow you to specify cleanup method. This, of course can
be done in many ways.
{ auto(:$critsec, :exit); @critsec.enter; … }
Critcal sections are better handled by blocks …
lock(mutex) do
# critical section
end
Like files, except when you want both at the same time. You can probably get
a way with nesting though.
i take it back, my problems still occur even if i call rb_gc directly from
some native method i write, — i’ll investigate if this is my fault instead
of ruby’s
cheers
···
-----Original Message-----
From: Gaffer [mailto:gaffer@gaffer.org]
Sent: Sunday, May 18, 2003 10:10 PM
To: ruby-talk ML
Subject: Re: ruby garbage collection
strange, i found the rb_gc call on my own and called that to good effect
(after a nasty false start with rb_gc_force_recycle exported on one of my
objects)
it seems to work, where calling GC.start from ruby still has the slowdown
for about 10secs, as if some background processing is going on
cant really explain what i’m experiencing then, if rb_gc_start just calls
rb_gc directly
cheers
-----Original Message-----
From: Mauricio Fernandez [mailto:batsman.geo@yahoo.com]
Sent: Sunday, May 18, 2003 9:57 PM
To: ruby-talk ML
Subject: Re: ruby garbage collection
On Sun, May 18, 2003 at 08:35:11PM +0900, Gaffer wrote:
i need this for a realtime game application which has embedded ruby –
after
destroying all objects in my scene and recreating everything, ruby gc
takes
about 10seconds to ‘think it through’ and collect all garbage… during
which time the framerate drops in half
i’d much rather it was all done in one hit in between levels, but i cannot
find an API to do this, and GC.start seems async
so,
assuming GC.start is asynchronous, is there a way to force mark/sweep GC
to
occur, blocking for however long it takes to complete?
AFAIK GC.start forces GC to take place right away:
gc.c
it seems to work, where calling GC.start from ruby still has the slowdown
for about 10secs, as if some background processing is going on
are you marking ruby instances yourself ?
can you estimate roughly how many ruby-instances you have ?
B: 500 < n < 5000
C: 5000 < n < 50000
D: 50000 < n < infinite
perhaps you are having a thread which is consuming all time ?
maybe pause all threads during GC can help (untested).
rb_thread_stop_timer();
rb_gc_start();
rb_thread_start_timer();
···
On Sun, 18 May 2003 22:10:18 +0900, Gaffer wrote:
A: 0 < n < 500
The syntax is not a big deal. One idea is to allow “auto” to take a
list of variables. Here’s another idea that’s more general approach
(although a bit more verbose …)
auto_block do |closer|
a = closer.register(Thing.new) { |thing| thing.close }
b = closer.register(Stuff.new) { |x| x.shut_down }
# do stuff with a & b…
end # closer will close anything registered with it.
fine if you can handle multiple objects this way. Mauricios suggestion does
that, but does not allow you to specify cleanup method. This, of course can
be done in many ways.
It seems you overlooked the fact that it is not implementable in current
Ruby, for it needs Procs to be rebound
It’d be easy to change it to specify the cleanup method, should it run
at all.
def auto(hash)
…
end
and then
auto( :a => :finalize, :file => close ) do
file = File.new(“/tmp/bla”)
a = Something.new
end
···
On Wed, May 21, 2003 at 05:14:06AM +0900, MikkelFJ wrote:
“Jim Weirich” jweirich@one.net wrote in message
news:1053406677.17559.8.camel@traken…
How about this syntax …
auto(foo=MyObject.new, :cleanup) do
# use foo
end
fine if you can handle multiple objects this way. Mauricios suggestion does
that, but does not allow you to specify cleanup method. This, of course can
be done in many ways.
i think its actually the GC cleaning up matrix and vector classes (my own
implementation extended in ruby, they just alloc and free using c++
new/delete operators, matching my c++ classes: vector (float[4]} and matrix
float[16];
the slowdowns appear to be caused by the gc collecting at longer and longer
intervals, – initially it works quite well, and it gc’s every sec or faster
later on it seems to buffer up gc for about 5-10 secs, and takes a good
chunk of time each sweep
also, i’m not doing any marking myself in c, these are pretty primitive c++
classes, and never ref any other ruby objects, so i just implement the free
function ptr for the classes
cheers
···
-----Original Message-----
From: Simon Strandgaard [mailto:0bz63fz3m1qt3001@sneakemail.com]
Sent: Sunday, May 18, 2003 10:30 PM
To: ruby-talk ML
Subject: Re: ruby garbage collection
On Sun, 18 May 2003 22:10:18 +0900, Gaffer wrote:
it seems to work, where calling GC.start from ruby still has the slowdown
for about 10secs, as if some background processing is going on
are you marking ruby instances yourself ?
can you estimate roughly how many ruby-instances you have ?
A: 0 < n < 500
B: 500 < n < 5000
C: 5000 < n < 50000
D: 50000 < n < infinite
perhaps you are having a thread which is consuming all time ?
maybe pause all threads during GC can help (untested).
rb_thread_stop_timer();
rb_gc_start();
rb_thread_start_timer();
“Jim Weirich” jweirich@one.net wrote in message
news:1053406677.17559.8.camel@traken…
How about this syntax …
auto(foo=MyObject.new, :cleanup) do
# use foo
end
fine if you can handle multiple objects this way. Mauricios suggestion
does
that, but does not allow you to specify cleanup method. This, of
course can
be done in many ways.
It seems you overlooked the fact that it is not implementable in current
Ruby, for it needs Procs to be rebound
I’m not sure, whether I understand you correctly. The solution below does
work. Why then is it not possible without rebinding procs?
It’d be easy to change it to specify the cleanup method, should it run
at all.
def auto(hash)
…
end
and then
auto( :a => :finalize, :file => close ) do
file = File.new(“/tmp/bla”)
a = Something.new
end
How about:
def auto2( hash )
begin
yield
ensure
hash.each do |obj, method|
obj.send method
end
end
end
class Foo
def cleanup
puts “cleanup”
end
end
auto2( Foo.new => :cleanup ) do
puts “in block”
end
robert
···
On Wed, May 21, 2003 at 05:14:06AM +0900, MikkelFJ wrote:
i think its actually the GC cleaning up matrix and vector classes (my own
implementation extended in ruby, they just alloc and free using c++
new/delete operators, matching my c++ classes: vector (float[4]} and matrix
float[16];
Can you reveal some of this code ?
also, i’m not doing any marking myself in c, these are pretty primitive c++
classes, and never ref any other ruby objects, so i just implement the free
function ptr for the classes
i’m pretty sure i’ve tracked down the cause, this is my first time embedding
ruby and writing classes in c++,
so i didnt know you could override the singleton method new for a class, to
do the Data_Make_Struct,
so i was wrapping an outer ‘husk’ object with a member variable @data which
was pointing to a Data_Wrap_Struct around my c++ object created with new
pretty nasty, and i have no idea how the gc would have interpreted this (as
i did no marking)
now that i’ve deciphered how everything should work, my matrix/vector
classes should be as efficient as they should have always been with ruby
i’ll post back when i have results, cheers
···
-----Original Message-----
From: Simon Strandgaard [mailto:0bz63fz3m1qt3001@sneakemail.com]
Sent: Sunday, May 18, 2003 11:30 PM
To: ruby-talk ML
Subject: Re: ruby garbage collection
On Sun, 18 May 2003 22:39:17 +0900, Gaffer wrote:
i think its actually the GC cleaning up matrix and vector classes (my own
implementation extended in ruby, they just alloc and free using c++
new/delete operators, matching my c++ classes: vector (float[4]} and
matrix
float[16];
Can you reveal some of this code ?
also, i’m not doing any marking myself in c, these are pretty primitive
c++
classes, and never ref any other ruby objects, so i just implement the
free
function ptr for the classes
warning! dont try to manually do the pointer wrapping, ruby already does it
for you! heheh
···
-----Original Message-----
From: Gaffer [mailto:gaffer@gaffer.org]
Sent: Sunday, May 18, 2003 11:48 PM
To: ruby-talk ML
Subject: Re: ruby garbage collection
i’m pretty sure i’ve tracked down the cause, this is my first time embedding
ruby and writing classes in c++,
so i didnt know you could override the singleton method new for a class, to
do the Data_Make_Struct,
so i was wrapping an outer ‘husk’ object with a member variable @data which
was pointing to a Data_Wrap_Struct around my c++ object created with new
pretty nasty, and i have no idea how the gc would have interpreted this (as
i did no marking)
now that i’ve deciphered how everything should work, my matrix/vector
classes should be as efficient as they should have always been with ruby
i’ll post back when i have results, cheers
-----Original Message-----
From: Simon Strandgaard [mailto:0bz63fz3m1qt3001@sneakemail.com]
Sent: Sunday, May 18, 2003 11:30 PM
To: ruby-talk ML
Subject: Re: ruby garbage collection
On Sun, 18 May 2003 22:39:17 +0900, Gaffer wrote:
i think its actually the GC cleaning up matrix and vector classes (my own
implementation extended in ruby, they just alloc and free using c++
new/delete operators, matching my c++ classes: vector (float[4]} and
matrix
float[16];
Can you reveal some of this code ?
also, i’m not doing any marking myself in c, these are pretty primitive
c++
classes, and never ref any other ruby objects, so i just implement the
free
function ptr for the classes
i’ve switched over all my ‘concrete’ classes quite easily, looks like i’ll
have to do some placement new (finally an excuse to use it) tricks for my
more complex classes
but its all working fine now, cheers
···
-----Original Message-----
From: Simon Strandgaard [mailto:0bz63fz3m1qt3001@sneakemail.com]
Sent: Monday, May 19, 2003 12:10 AM
To: ruby-talk ML
Subject: Re: ruby garbage collection
On Sun, 18 May 2003 23:48:28 +0900, Gaffer wrote:
so i didnt know you could override the singleton method new for a class,
to
do the Data_Make_Struct,
Yeah its a bastard
so i was wrapping an outer ‘husk’ object with a member variable @data
which
was pointing to a Data_Wrap_Struct around my c++ object created with new
Yes… My alloc/free looks something like this (ruby-1.8.0)
void Free(Klass *p) {
delete p;
}
VALUE Alloc(VALUE self) {
Klass* p = new Klass();
return Data_Wrap_Struct(self, 0, Free, p);
}
void KlassInit() {
VALUE h = rb_define_class(“Klass”, rb_cObject);
rb_define_alloc_func(h, Alloc);
}
an interesting aside, is there any benefit to using ruby’s ALLOC etc.
functions over new/delete? i notice you dont, cheers
···
-----Original Message-----
From: Simon Strandgaard [mailto:0bz63fz3m1qt3001@sneakemail.com]
Sent: Monday, May 19, 2003 12:10 AM
To: ruby-talk ML
Subject: Re: ruby garbage collection
On Sun, 18 May 2003 23:48:28 +0900, Gaffer wrote:
so i didnt know you could override the singleton method new for a class,
to
do the Data_Make_Struct,
Yeah its a bastard
so i was wrapping an outer ‘husk’ object with a member variable @data
which
was pointing to a Data_Wrap_Struct around my c++ object created with new
Yes… My alloc/free looks something like this (ruby-1.8.0)
void Free(Klass *p) {
delete p;
}
VALUE Alloc(VALUE self) {
Klass* p = new Klass();
return Data_Wrap_Struct(self, 0, Free, p);
}
void KlassInit() {
VALUE h = rb_define_class(“Klass”, rb_cObject);
rb_define_alloc_func(h, Alloc);
}