f3 and f5 memory issue view

Former Member
Former Member
Hi,
I add some compatibilities to the fenix 5 to my datafields.
As there is different font now, I made some tests on my drawlayout by doing something like :

if(dc.getHeight == 240 && dc.getWidth == 240 ) { // code for f5X } else ...


But by doing this (many times), I've a memory issue on my f3 ...

Is there any better way for making this ?

Thanks for your help.

Rgds,
  • One thing is that it should be dc.getWidth() and dc.getHeight(), and not dc.getWidth and dc.getHeight.

    Then the question is where are you doing it and what are you doing?

    (I'd do this in onLayout(), and set some things that are used in onUpdate() myself). How big (memory wise) was the DF before you changed it? If it was 15.9k peak, it's hard to do much and stay under the 16k max on the f3.
  • Former Member
    Former Member
    I was very high in memory before (in fact, it didn't work in the simulator on f3, but works on watches) .

    yes, it is dc.getWidth() and dc.getHeight().

    I use them in drawLayout(dc) and in onUpdate(dc) :

    I made for example :

    if(dc.getHeight() == 240 && dc.getWidth() == 240 ) {
    dc.drawText(dc, 80, 120, Graphics.FONT_MEDIUM, fields.time, Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);

    }


    else {
    dc.drawText(dc, 70, 100, Graphics.FONT_MEDIUM, fields.time, Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);

    }






    In the Connect IQ store, I believe I see upgrades on app with the comment : 'additional features for watches with big memory' ... Then, I was hoping to be able to keep my old code that was working on f3, and with a special parameter , said to read the other code, then the memory will not change.
  • if(dc.getHeight() == 240 && dc.getWidth() == 240 ) {
    dc.drawText(dc, 80, 120, Graphics.FONT_MEDIUM, fields.time, Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);

    }


    else {
    dc.drawText(dc, 70, 100, Graphics.FONT_MEDIUM, fields.time, Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);

    }






    what I'd do is something like this to saves a bit. I'd do it in onLayout().

    myX=70;
    myY=100;
    if(dc.getWidth()==240 && dc.getHeight()==240) {
    myX=80;
    myY=120;
    }

    and then in onUpdate() just do

    dc.drawText(myX,myY, Graphics.FONT_MEDIUM, fields.time, Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);

    (you only have the drawText once in your code and not twice, and not check each time onUpdate() is called.) BTW, is that a typo with dc as a parameter to dc.drawText()?)

    it all kind of depends on how close you are to 16k for the f3. If you can't run the original version in the sim, that to me says you first need to get that smaller so it will run in the sim as you are right at the edge already....
  • Former Member
    Former Member
    Yes, it was a typo for the dc in the drawText ... I don't have the code in front of me, then I made mistake with my minds ...

    Thanks for the tip ... I'll try it ...

    Rgds,
  • if you are doing the check a number of times in onUpdate() (with different dc.drawText() calls, etc), you can save a bit by just setting the x and y in onLayout() and removing all the conditionals in onUpdate(). But if you're right on the edge with the original code, you'll likely need to rework some of the base code too.
  • Former Member
    Former Member
    I've a lot of dc.drawText() calls in my onupdate() then I guess that it'll work.

    But as I've a lot of calls, I'll need to create a lot of variable like myX, myY, and I hope that this will not take a lot memory ...