как установить привязку ЦП программы?

В этом случае

sb.setLength(sb.length() - 1);

предпочтительнее, так как он просто присваивает последнее значение '\0', тогда как удаление последнего символа делает System.arraycopy

11
задан George2 27 June 2009 в 07:09
поделиться

3 ответа

The Windows API functions to do this are SetProcessAffinityMask() and SetThreadAffinityMask(). I don't know .NET so I can't say whether there are wrappers around those functions, but this seems to suggest otherwise.

BTW: I agree that these are necessary only in very specific circumstances, it's normally best to let the OS scheduler deal with it. It's one of those questions where you probably shouldn't do it if you have to ask how.

7
ответ дан 3 December 2019 в 04:53
поделиться
  1. Go to Task Manager -> Processes tab.
  2. Look for your program. Right click on it.
  3. Select Set Affinity and uncheck one of the checkboxes.

This should free up one processor for you.

For doing it from the code you can add this statement:

System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr) 1;

Cheers!

13
ответ дан 3 December 2019 в 04:53
поделиться

Actually, your application will not use more than one CPU unless you specifically do something to utilize more CPUs. If you use the thread pool and/or start additional threads you may use additional available cores, but otherwise your application will just have one thread per default and thus only use one CPU.

3
ответ дан 3 December 2019 в 04:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: