Python Forum
Drawing a sine curve in memory view of Task Manager
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drawing a sine curve in memory view of Task Manager
#1
Question 
Hi guys [Image: icon_e_smile.gif]

I am trying to write a simple proof-of-concept script on Windows 10 that let's me draw the absolute of a sin curve in the task manager memory window.

My code is as follows:

import time
import math
import gc
import sys

x = 1
string_drawer = []

while True:

    #Formula for the eqaution (sin curve)
    y = (abs(math.sin(math.radians(100*x))))*512000000
    print (y, type(y))

    #Making y type 'int' so that it can be used to append
    y = int(round(y))
    print (y, type(y))

    #Checking the size of string_drawer for debugging
    print(sys.getsizeof(string_drawer))

    #Loop used for appending
    if sys.getsizeof(string_drawer) < y: #If y is bigger, find the difference and append

        y = y - sys.getsizeof(string_drawer)
        string_drawer.append(' ' *y)

    elif sys.getsizeof(string_drawer) > y: #If y is smaller, delete the variable and make a new one

        string_drawer = [] *y

    else: #If y is the same size as string_drawer, do nothing

        pass

    #Call the Python gerbage colector
    gc.collect()

    #Sleep to make sure Task Manager catches the change in RAM usage
    time.sleep(0.5)

    #Increment x
    x += 1
    print(x, type(x))
What I am getting is this:
[Image: ahEsx.png]

What I want is this:
[Image: UXPYc.png]

I am not entirely sure what I am doing wrong, but I suspect it is something to do with the garbage collection in Python. I've extensively searched for the answer, but I didn't find anything that worked...

I hope you guys can help me. Thanks!
Reply
#2
See my answer to your answer on the other forum?

This forum is the newer version of the other one, the same people answer...
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
The garbace will not be collected immediately when you call it, but at some arbitrary time, which can't be influenced directly. It depends on many things, maybe that is why you see the slow build-up and sharp decline there. By the way, which concept are you proofing? :D
Reply
#4
Doh... Now I understand what you want... Highly unlikely to work. Even assuming that the GC actually does something when you call it, it won't always return te recovered memory to the system.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#5
(Sep-19-2016, 02:02 PM)Kebap Wrote: The garbace will not be collected immediately when you call it, but at some arbitrary time, which can't be influenced directly. It depends on many things, maybe that is why you see the slow build-up and sharp decline there. By the way, which concept are you proofing? :D

We started doing something about memory in my CS class, and then I had maths where we had some graphing exercises. I was wondering if what I want to do is possible. That's really it :P

(Sep-19-2016, 07:00 PM)Ofnuts Wrote: Doh... Now I understand what you want... Highly unlikely to work. Even assuming that the GC actually does something when you call it, it won't always return te recovered memory to the system.

Ok, I seem to understand. I've read here(https://stackoverflow.com/questions/1545...-in-python) that if I spawn child processes, it shoudl release the memory back to the system. Another alternative I have thought of is making a 2D array, where each row is a diffferent length to correspond to how much memory must be used, and then deleting the rows in such a way that they create a sine curve. However, I don't know if I could get around the garbage collector issue that way :/
Reply
#6
Another solution:

Create many subprocesses:
  • All subprocesses will try to grab a visible chunk of memory (say 50M).
  • You start the processes at regular intervals, and each process exits after some delay, that is specific to it, with processes started first having longer lifespans.
  • So the first process grabs memory for 20 seconds, the seconds starts one second later but has a lifespan of 18 secs, and the third has a life span of 16 seconds, etc.
  • Once you detect the end of the first process, do it again.
This should create a (stepped) triangular wave. By adjusting the delays and the life spans, you can approximate your curve.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Learning curve astral_travel 1 219 Mar-10-2024, 08:00 AM
Last Post: snippsat
  How can I design shapes on a curve in python? mervea 2 765 Sep-14-2023, 01:04 PM
Last Post: Pedroski55
  Fitting data to a curve daaegp 1 567 Jun-30-2023, 08:06 PM
Last Post: Gribouillis
  count certain task in task manager[solved] kucingkembar 2 1,083 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Find factor to match test curve to golden curve SriRajesh 0 1,522 Jun-17-2021, 04:39 AM
Last Post: SriRajesh
  Fitting Gaussian curve to data file Laplace12 0 2,672 Jun-09-2021, 10:45 AM
Last Post: Laplace12
  Schedule a task and render/ use the result of the task in any given time klllmmm 2 2,033 May-04-2021, 10:17 AM
Last Post: klllmmm
  How to create a task/import a task(task scheduler) using python Tyrel 7 3,628 Feb-11-2021, 11:45 AM
Last Post: Tyrel
  search of a curve fitting function bluffy5 2 2,377 Dec-13-2020, 09:53 AM
Last Post: ndc85430
  How to create an app manager _ShevaKadu 8 3,695 Nov-01-2020, 12:47 PM
Last Post: _ShevaKadu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020