Life of allocated hub
4x5n
Posts: 745
I've been thinking about a method to allow various objects and methods running on different cogs to pass information back and forth. My thought is to have have the initial method/object reserve an array as global memory and then pass the address of the array to the different objects. This way an object can pass data to other objects.
I'm doing something like it already in other short programs I've written. Rather then having an objects stop method simply cut out a method at it's knees by stopping a cog and then having to clean up the mess I have the stop method set a "stop" variable that's global to the object which is "monitored" by the other methods in the object and when set it's set causes the method to shut itself down and when it's done shuts down the cog.
My question is if during the run of the "program" I stop cog 0 and use it for something else does the memory it reserved become available for other use?
I'm doing something like it already in other short programs I've written. Rather then having an objects stop method simply cut out a method at it's knees by stopping a cog and then having to clean up the mess I have the stop method set a "stop" variable that's global to the object which is "monitored" by the other methods in the object and when set it's set causes the method to shut itself down and when it's done shuts down the cog.
My question is if during the run of the "program" I stop cog 0 and use it for something else does the memory it reserved become available for other use?
Comments
It's not hard to reuse the program space of PASM code since it all grouped together. This is a semi common practice already. Finding where the Spin code is stored in hub RAM is more involved but I think others have done it.
Dr_Acula uses cogjects. Objects that are all PASM (or are they mostly PASM) which makes reusing their memory easier.
Duane
Stopping a COG will effectively destroy the code. You don't need to stop a COG though as you have already realized. Many people use mailboxes for HUB/COG communications - it is not an advanced concept. All you have to do is share the variable via the PAR register. The COG can "SPIN" on the PAR pointer waiting for a command to be non-zero, go do work, signal it is finished, and spin again.
Hope this helps.
--Steve