mutable int, float



  • 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



  • 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
    

Log in to reply
 

Pycom on Twitter