Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    mutable int, float

    Scheduled Pinned Locked Moved MicroPython
    mutablefreemem
    2 Posts 2 Posters 876 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      livius
      last edited by

      Is there a way that i can change float but do not create another one in memory?
      Or free this intermediate by del without need to run gc.collect()?
      sample:

      f1=5
      f2=2
      f1*=f2 # this line eat memory
      

      how to avoid this eat of memory?
      if i do this in loop then whole memory will be eaten and i simpy got automatic gc.collect which take for me unacceptable wait

      i do 3 above operation in loop and in every loop i loose 3*16=48 bytes
      maybe it is not big - 1000 loop iteration
      but if i can avoid this i am really interested

      think about people first, then computers

      1 Reply Last reply Reply Quote 1
      • robert-hhR Offline
        robert-hh
        last edited by

        I think there is only little freedom. Floating point operations always allocate memory. Integer operations do not allocate memory as long as the result fits into 30 bit. Then memory must be allocated to store the result. Example on a LoPy:

        >>> f2 = 2
        >>> for _ in range(32):
        ...     f1 *= f2
        ...     print(_+1, end = " ")
        ...     gc.mem_free()
        ... 
        1 37408
        2 37408
        3 37408
        4 37408
        5 37408
        6 37408
        7 37408
        8 37408
        9 37408
        10 37408
        11 37408
        12 37408
        13 37408
        14 37408
        15 37408
        16 37408
        17 37408
        18 37408
        19 37408
        20 37408
        21 37408
        22 37408
        23 37408
        24 37408
        25 37408
        26 37408
        27 37408
        28 37408
        29 37408
        30 37344
        31 37312
        32 37280
        
        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom