control.ramSize What does it mean?

When printing control.ramSize to the control it prints the following:

function control_ramSize__P369579(s) {
let r0 = s.r0, step = s.pc;
s.pc = -1;
while (true) {
if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) return null;
switch (step) {
case 0:
r0 = pxsim_pxtcore.getConfig(205, 0);
s.tmp_0 = r0;
r0 = pxsim_numops_toBool(s.tmp_0);
if (!r0) { step = 1; continue; }
r0 = s.tmp_0;
{ step = 2; continue; }
case 1:
r0 = 33554432;
case 2:
// jmp value (already in r0)
s.tmp_1 = r0;
r0 = s.tmp_1;
return leave(s, r0)
default: oops()
} } }

What does it mean and why can it be run by just having the command on one line.

Hey, welcome to the forum :slight_smile:.

In general it’ll be way easier to figure out particular details like this by looking at the source when it’s available rather than the compiled js assembly equivalent; looks like you have to be signed in to view github code searches currently but this sort of search is how I’d typically find it if you are, otherwise can poke around starting from the user js level function, which calls into different things depending on the environment; in the browser you end up here, and here is the cpp function (+ a few other places it gets overrided for e.g. the raspberry pi build).

Long story short, it returns a number mapping to the number of bytes available (with an arbitrary, significantly larger amount than most supported hardware amount for the sim); one place I’ve used this in the past is in the implementation for particle effects to limit the number of concurrent effects based off device spec (so it can still look perfect in sim / higher powered devices, but doesn’t lead to crashes devices with the lowest supported spec by overusing memory).

1 Like

Yep! Seems like it works!