A technical question about RAM usage
If a top level object calls multiple instances of a sublevel object in separate cogs I understand that the
only penalty is stack space and a few management bytes. That is there is no multiple copies of the object’s code.
However, consider this scenario:
1-Top level starts a cog with the FullDuplexSerial object
2- Top level starts another cog with another object say AA
3- Object AA in the new cog starts another cog with the FullDuplexSerial
The question is….is the code of the second instance of the FullDuplexSerial going to be duplicated in RAM or
is the old instance’s code used again??
I know I can probably try this out and look at the memory map and try to figure out where
things are....but I am lazy and I am hoping someone can help me ...Please!
Sam
only penalty is stack space and a few management bytes. That is there is no multiple copies of the object’s code.
However, consider this scenario:
1-Top level starts a cog with the FullDuplexSerial object
2- Top level starts another cog with another object say AA
3- Object AA in the new cog starts another cog with the FullDuplexSerial
The question is….is the code of the second instance of the FullDuplexSerial going to be duplicated in RAM or
is the old instance’s code used again??
I know I can probably try this out and look at the memory map and try to figure out where
things are....but I am lazy and I am hoping someone can help me ...Please!
Sam
Comments
Main
|--FullDuplexSerial
|--SomeObject
|-FullDuplexSerial
Then the PUB, PRI and DAT sections for FullDuplexSerial will get included once and the VAR section will get included twice.
Hope that helps.
So, the answer is no, there is no duplication of code for each instance, concurrent or not. As mentioned by Steven, only the dynamic data is duplicated.
Say User3Of_FDS is the main program, which uses User2Of_FDS and UserOf_FDS. Eeach of those runs an instance of FullDuplexSerial, so we have 3 Serial interfaces running.
During compile the PropTool searches upward in the folder structure. So, for User2Of_FDS which uses FullDuplexSerial it immediately finds a version in the same folder. User3Of_FDS finds the same one, as it's the closest version it can find. UserOf_FDS·is in the top level folder and will find the FullDuplexSerial there. I don't think, that the compiler really checks whether the two FullDuplexSerial versions are the same or not.
Here file1.spin and file2.spin will generate the same spin bytecode and only one copy of the PUB, DAT and PRI sections will be included in the binary. Depending on what you are doing this may or may not be useful. Mostly it's useful because it stops you wasting space. However, occasionally you may actually want the DAT sections to be different. To do that all you need to do is change the value of the abc variable and then both copies will be included and you'll have two different DAT sections.