OG_OTT
Visitor

Difference between m and m.top

First Question: What is the difference between m and m.top?  I'm coming from various languages... C/CPP, Python, C#, JavaScript.  

Assumptions:  Based on the "Data Scoping" SDK article it sounds like "m" reference is used more like "private" in other languages (scope is available to the component but no other actor/instance), and "m.top" is used as a way to take "m" private references and expose them to parent ScreenGraph nodes (aka making them public?).  This is just my guess after what I have read, but I'm looking to bring it back to one of the languages that I already understand... Can anyone help make the connection for me?

Second/Third (Bonus) Question:

  • Are there any good patterns/advice you can offer on when to use "m" versus "m.top"?

  • Are there any "gotchas" that I should be aware of for "m" vs "m.top" like:

  1. memory, 

  2. latency, 

  3. de-reference concerns, 

  4. race conditions, 

  5. garbage collection, 

  6. performance?

As always, thank you to this forum for being very supportive (and not flaming/trolling) =P.  At least to my first 3 posts!

To answer my own question (and failed), I have done the following
Tags (1)
3 REPLIES 3
joetesta
Roku Guru

Re: Difference between m and m.top

"m" is the private local associative array (the doc calls it "the m object reference")
"top" a default element of m, node reference that refers to the component itself.  m.top should be used sparingly and only when needed to set and observe fields from outside the node.  you can use m to hold local data, functions, and all kinds of things (objects and sub-components) to help build up your screen experience.
https://sdkdocs.roku.com/display/sdkdoc/SceneGraph+Data+Scoping
oh you listed that one, yeah it's not very deep.  Basic rule of thumb, always use m and never m.top unless you have to.
aspiring
Tags (1)
OG_OTT
Visitor

Re: Difference between m and m.top

so just rephrasing what I think I understood...

`m` is equiv to 'this' or `self` in a lot of other languages.  `m` is closed/private to external agents.
`m.top` is part of object creation managed by BrightScript/RSG such that anything put into (or made as an entry/attribute/field/property w/e you want to call it) `m.top` automatically becomes part of the objects public scope and thus m.top will allow external agents access to read/edit and possibly expose implementation details of said object.

A different way to say it, but a way that I think I understood what you said (makes sense in my head).  Did I express anything that demonstrates I obviously missed the mark?

Thanks!
Tags (1)
0 Kudos
joetesta
Roku Guru

Re: Difference between m and m.top

`m.top` is part of object creation managed by BrightScript/RSG such that anything put into (or made as an entry/attribute/field/property w/e you want to call it) `m.top` automatically becomes part of the objects public scope and thus m.top will allow external agents access to read/edit and possibly expose implementation details of said object.


Yes though one point is that you can't just put anything into top; being that top is a node, you can append children nodes to it (that would usually cause something to show up on screen) or set fields on it, setting fields isn't automagic, the field has to be defined in component's interface fields or added with addField (or be a default field on node such as "id").

It's important to understand the difference between the types "node" and "associative array".; m is the latter and you can just put anything onto it, m.top is the former and has fields and child nodes.
aspiring
Tags (1)
0 Kudos
Community is Temporarily in Read-Only Mode!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. You will not be able to log in or post new comments or kudos during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 12 and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

Thanks for your patience — we’re excited to share what’s next!