frame as asm mem discussion

DSP related issues, mathematics, processing and techniques
Post Reply
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

frame as asm mem discussion

Post by KG_is_back »

I've had this idea the other day. Ruby constants are never garbage-collected (unless you do something very fishy with classes). Perhaps we can create a Hash constant GLOBAL_FRAMES and then put frames into it by their rubyedit as a key. That way we wouldn't have to trigger the module to prevent garbage collection.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: frame as asm mem discussion

Post by tulamide »

Careful with globals, specifically within Flowstone. We had a discussion about globals (and class variables, too) when Exo tried to find a way to have C-type callbacks.
Myco pointed out that not only one project uses only one Ruby, all running Flowstone projects share the same Ruby. And therefore a constant is valid for all those plugins and executables that run on your system. How should a plugin differentiate constants with the same name? It can't. So the first definition of a constant stays valid for all. With class variables you could at least manage some kind of inter-application-communication, although still not very safe. But with constants you're risking too much.
"There lies the dog buried" (German saying translated literally)
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: frame as asm mem discussion

Post by KG_is_back »

Example code:

Code: Select all

#declare constant if not declared yet
if not(GLOBAL_FRAMES)
GLOBAL_FRAMES=Hash.new(Frame.new(1) #hash with default value (empty frame)
end

def event(i,v,t) #input is an array
nf=Frame.new(v)
#here should be code, that outputs size and address of new frame

GLOBAL_FRAMES[self]=nf #notice that current rubyEdit is used as a key

end


From what I can tell "self" is a unique object for each rubyedit, so no interference should happen (each rubyedit will have unique key for its personal frame). Also the "GLOBAL_FRAMES" constant is initialized only once. Unless some of your projects use constant with the same name for something else than storing frames this way, there should be no interference at all. AFAIK the rubyEdit instances should be each unique (even if multiple copies of the same project exist) in a role of hash key, right?
Post Reply