Jump to content

Gurus Help me

Little Bear

            

This is inside a while loop, and somehow I need to call upon it elsewhere to make a function.

 

                int currentCpuPercentage = (int)perfCpuCount.NextValue();
                int currentAvailableMemory = (int)perfMemCount.NextValue();
                int currentTemperature = (int)((((perfTemperature.NextValue() / 3) - 32) * 5) / 9);

 

 

If you need more source code let me know. <3 thanks!

Motivation is where, and what you make of it.

 

“It is relatively unusual that a physical scientist is truly an atheist. Why is this true? Some point to the anthropic constraints, the remarkable fine tuning of the universe. For example, Freeman Dyson, a Princeton faculty member, has said, ‘Nature has been kinder to us that we had any right to expect.'”  Albert Einstein

Link to comment
Share on other sites

Link to post
Share on other sites

Why not put these three lines in another function and put in the while loop a command that run that function? And from the other place you want to access these three lines you can also just call that function

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

I am relatively new to C, so to me its not really simple :P,  but I can't do that because its calling on performance counters inside of the loop.

Motivation is where, and what you make of it.

 

“It is relatively unusual that a physical scientist is truly an atheist. Why is this true? Some point to the anthropic constraints, the remarkable fine tuning of the universe. For example, Freeman Dyson, a Princeton faculty member, has said, ‘Nature has been kinder to us that we had any right to expect.'”  Albert Einstein

Link to comment
Share on other sites

Link to post
Share on other sites

Yeah, if you ever write the same code twice make it a function and call it. What

while('this is you centry for loop')
{
	ReadCPU();
}

void ReadCPU();
{
	int currentCpuPercentage = (int)perfCpuCount.NextValue();
    int currentAvailableMemory = (int)perfMemCount.NextValue();
    int currentTemperature = (int)((((perfTemperature.NextValue() / 3) - 32) * 5) / 9);
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, jimistephen said:

Yeah, if you ever write the same code twice make it a function and call it. What


while('this is you centry for loop)
{
	ReadCPU();
}

void ReadCPU();
{
	int currentCpuPercentage = (int)perfCpuCount.NextValue();
    int currentAvailableMemory = (int)perfMemCount.NextValue();
    int currentTemperature = (int)((((perfTemperature.NextValue() / 3) - 32) * 5) / 9);
}

 

I will try this.

Motivation is where, and what you make of it.

 

“It is relatively unusual that a physical scientist is truly an atheist. Why is this true? Some point to the anthropic constraints, the remarkable fine tuning of the universe. For example, Freeman Dyson, a Princeton faculty member, has said, ‘Nature has been kinder to us that we had any right to expect.'”  Albert Einstein

Link to comment
Share on other sites

Link to post
Share on other sites

It can't call upon the performance counters now

 

Source code removed

Motivation is where, and what you make of it.

 

“It is relatively unusual that a physical scientist is truly an atheist. Why is this true? Some point to the anthropic constraints, the remarkable fine tuning of the universe. For example, Freeman Dyson, a Princeton faculty member, has said, ‘Nature has been kinder to us that we had any right to expect.'”  Albert Einstein

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Little Bear said:

It can't call upon the performance counters now

 

Source code removed

 
 

Probably because it loses access to the variables perfCpuCount, perfMemCount, and perfTemperature.

 

You can pass information into a function through its parameters. Here's a very simple example

void Main()
{
    int i = 2;
    int j = 3;
    int result = Add(i, j);
}

public static int Add(int x, int y)
{
    return x + y;
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

If calling a function is too much of a performance hit, consider making it a macro

Solve your own audio issues  |  First Steps with RPi 3  |  Humidity & Condensation  |  Sleep & Hibernation  |  Overclocking RAM  |  Making Backups  |  Displays  |  4K / 8K / 16K / etc.  |  Do I need 80+ Platinum?

If you can read this you're using the wrong theme.  You can change it at the bottom.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Ryan_Vickers said:

If calling a function is too much of a performance hit, consider making it a macro

Based on his other recent thread, I think he's using C# and not C (as he said above). I could be wrong though.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, madknight3 said:

Based on his other recent thread, I think he's using C# and not C (as he said above). I could be wrong though.

oh, then I will be no help probably :P

Solve your own audio issues  |  First Steps with RPi 3  |  Humidity & Condensation  |  Sleep & Hibernation  |  Overclocking RAM  |  Making Backups  |  Displays  |  4K / 8K / 16K / etc.  |  Do I need 80+ Platinum?

If you can read this you're using the wrong theme.  You can change it at the bottom.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, madknight3 said:

Based on his other recent thread, I think he's using C# and not C (as he said above). I could be wrong though.

You are correct, and the problem is: I have performance counters in my loop (where they need to be) then i have functions to declare them in the loop (where the need to be for some other code to work), but with those two things configured that way how could i call upon in outside of the while loop(I need those specific variables)?

Motivation is where, and what you make of it.

 

“It is relatively unusual that a physical scientist is truly an atheist. Why is this true? Some point to the anthropic constraints, the remarkable fine tuning of the universe. For example, Freeman Dyson, a Princeton faculty member, has said, ‘Nature has been kinder to us that we had any right to expect.'”  Albert Einstein

Link to comment
Share on other sites

Link to post
Share on other sites

27 minutes ago, Little Bear said:

You are correct, and the problem is: I have performance counters in my loop (where they need to be) then i have functions to declare them in the loop (where the need to be for some other code to work), but with those two things configured that way how could i call upon in outside of the while loop(I need those specific variables)?

Put the functions to declare them outside the loop. And also outside of the block of code the loop is inside so you can call them from anywhere.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Little Bear said:

You are correct, and the problem is: I have performance counters in my loop (where they need to be) then i have functions to declare them in the loop (where the need to be for some other code to work), but with those two things configured that way how could i call upon in outside of the while loop(I need those specific variables)?

 
 

It's much easier to help when you show us the code.

Link to comment
Share on other sites

Link to post
Share on other sites

Removed

Motivation is where, and what you make of it.

 

“It is relatively unusual that a physical scientist is truly an atheist. Why is this true? Some point to the anthropic constraints, the remarkable fine tuning of the universe. For example, Freeman Dyson, a Princeton faculty member, has said, ‘Nature has been kinder to us that we had any right to expect.'”  Albert Einstein

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×