[Source]Affinity Checker/Core amount

Discussion in 'Programming General' started by halojunkie, Jul 13, 2008.

[Source]Affinity Checker/Core amount
  1. Unread #1 - Jul 13, 2008 at 3:06 AM
  2. halojunkie
    Joined:
    Dec 17, 2005
    Posts:
    232
    Referrals:
    0
    Sythe Gold:
    0

    halojunkie Active Member

    [Source]Affinity Checker/Core amount

    NOTE: Not written by me, but passed on to you by me :D

    Code:
    Declare Function GetProcessAffinityMask Lib "kernel32" (ByVal hProcess As Long, lpProcessAffinityMask As Long, SystemAffinityMask As Long) As Long
    Declare Function GetCurrentProcess Lib "Kernel32.dll" () As Long
    
    Public Function Check_Affinity() As String
        Dim ProcMask As Long, SysMask As Long
        
        Dim Num_Procs As Long
        Dim i As Long, j As Long
        
        Call GetProcessAffinityMask(GetCurrentProcess(), ProcMask, SysMask)
    
        ' Number of binary digits in this mask is the highest processor index.
        ' Number of radix-n digits in a number, x, is Int( Log_n(x) ) = Log(x)/Log(n)
        ' SysMask = 2^np - 1... Log_2(SysMask + 1) = np
        Num_Procs = Math.Log(CDbl(SysMask) + 1) / Math.Log(2)
        
        j = 1
        For i = 1 To Num_Procs
            If ProcMask And j Then
                ' Affinity with processor i-1, counted from 0
                Check_Affinity = Check_Affinity & i - 1 & ", "
            End If
            j = j * 2
        Next
        
        If Len(Check_Affinity) > 0 Then
            Check_Affinity = "Cores: " & Left(Check_Affinity, Len(Check_Affinity) - 2)
        Else
            ' I don't think it's possible to get here
            ' but this may indicate an error.
            Check_Affinity = "No affinity?"
        End If
    End Function
     
  3. Unread #2 - Jul 13, 2008 at 7:06 AM
  4. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [Source]Affinity Checker/Core amount

    Excuse my ignorance, but what's it do? (Moniter's Affinity, but what's that on your system?)
     
  5. Unread #3 - Jul 13, 2008 at 10:27 PM
  6. brownhead
    Referrals:
    0

    brownhead Guest

    [Source]Affinity Checker/Core amount

    Its for multiple processors... I don't know why he would post this here..
     
< [VB 2008 Source] Skill Calculator | What is this? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site