Win32 API 日本語リファレンス
ホームSystem.SystemInformation › CACHE_RELATIONSHIP

CACHE_RELATIONSHIP

構造体
サイズx64: 48 バイト / x86: 44 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
LevelBYTE1+0+0キャッシュの階層レベル(L1〜L3 等)。
AssociativityBYTE1+1+1キャッシュの連想度(ウェイ数)。0xFF は完全連想。
LineSizeWORD2+2+2キャッシュラインのサイズ。バイト単位。
CacheSizeDWORD4+4+4キャッシュの総容量。バイト単位。
TypePROCESSOR_CACHE_TYPE4+8+8キャッシュの種類を示す PROCESSOR_CACHE_TYPE。
ReservedBYTE18+12+12予約済みフィールド。
GroupCountWORD2+30+30Anonymous が保持するグループアフィニティの数。
Anonymous_Anonymous_e__Union16/12+32+32キャッシュを共有するプロセッサのグループアフィニティを保持する無名共用体。

共用体: _Anonymous_e__Union x64 16B / x86 12B

フィールドサイズx64x86
GroupMaskGROUP_AFFINITY16/12+0+0
GroupMasksGROUP_AFFINITY16/12+0+0

各言語での定義

#include <windows.h>

// CACHE_RELATIONSHIP  (x64 48 / x86 44 バイト)
typedef struct CACHE_RELATIONSHIP {
    BYTE Level;
    BYTE Associativity;
    WORD LineSize;
    DWORD CacheSize;
    PROCESSOR_CACHE_TYPE Type;
    BYTE Reserved[18];
    WORD GroupCount;
    _Anonymous_e__Union Anonymous;
} CACHE_RELATIONSHIP;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CACHE_RELATIONSHIP
{
    public byte Level;
    public byte Associativity;
    public ushort LineSize;
    public uint CacheSize;
    public int Type;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)] public byte[] Reserved;
    public ushort GroupCount;
    public _Anonymous_e__Union Anonymous;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CACHE_RELATIONSHIP
    Public Level As Byte
    Public Associativity As Byte
    Public LineSize As UShort
    Public CacheSize As UInteger
    Public Type As Integer
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=18)> Public Reserved() As Byte
    Public GroupCount As UShort
    Public Anonymous As _Anonymous_e__Union
End Structure
import ctypes
from ctypes import wintypes

class CACHE_RELATIONSHIP(ctypes.Structure):
    _fields_ = [
        ("Level", ctypes.c_ubyte),
        ("Associativity", ctypes.c_ubyte),
        ("LineSize", ctypes.c_ushort),
        ("CacheSize", wintypes.DWORD),
        ("Type", ctypes.c_int),
        ("Reserved", ctypes.c_ubyte * 18),
        ("GroupCount", ctypes.c_ushort),
        ("Anonymous", _Anonymous_e__Union),
    ]
#[repr(C)]
pub struct CACHE_RELATIONSHIP {
    pub Level: u8,
    pub Associativity: u8,
    pub LineSize: u16,
    pub CacheSize: u32,
    pub Type: i32,
    pub Reserved: [u8; 18],
    pub GroupCount: u16,
    pub Anonymous: _Anonymous_e__Union,
}
import "golang.org/x/sys/windows"

type CACHE_RELATIONSHIP struct {
	Level byte
	Associativity byte
	LineSize uint16
	CacheSize uint32
	Type int32
	Reserved [18]byte
	GroupCount uint16
	Anonymous _Anonymous_e__Union
}
type
  CACHE_RELATIONSHIP = record
    Level: Byte;
    Associativity: Byte;
    LineSize: Word;
    CacheSize: DWORD;
    Type: Integer;
    Reserved: array[0..17] of Byte;
    GroupCount: Word;
    Anonymous: _Anonymous_e__Union;
  end;
const CACHE_RELATIONSHIP = extern struct {
    Level: u8,
    Associativity: u8,
    LineSize: u16,
    CacheSize: u32,
    Type: i32,
    Reserved: [18]u8,
    GroupCount: u16,
    Anonymous: _Anonymous_e__Union,
};
type
  CACHE_RELATIONSHIP {.bycopy.} = object
    Level: uint8
    Associativity: uint8
    LineSize: uint16
    CacheSize: uint32
    Type: int32
    Reserved: array[18, uint8]
    GroupCount: uint16
    Anonymous: _Anonymous_e__Union
struct CACHE_RELATIONSHIP
{
    ubyte Level;
    ubyte Associativity;
    ushort LineSize;
    uint CacheSize;
    int Type;
    ubyte[18] Reserved;
    ushort GroupCount;
    _Anonymous_e__Union Anonymous;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CACHE_RELATIONSHIP サイズ: 44 バイト(x86)
dim st, 11    ; 4byte整数×11(構造体サイズ 44 / 4 切り上げ)
; Level : BYTE (+0, 1byte)  poke st,0,値  /  値 = peek(st,0)
; Associativity : BYTE (+1, 1byte)  poke st,1,値  /  値 = peek(st,1)
; LineSize : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; CacheSize : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; Type : PROCESSOR_CACHE_TYPE (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; Reserved : BYTE (+12, 18byte)  varptr(st)+12 を基点に操作(18byte:入れ子/配列)
; GroupCount : WORD (+30, 2byte)  wpoke st,30,値  /  値 = wpeek(st,30)
; Anonymous : _Anonymous_e__Union (+32, 12byte)  varptr(st)+32 を基点に操作(12byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CACHE_RELATIONSHIP サイズ: 48 バイト(x64)
dim st, 12    ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; Level : BYTE (+0, 1byte)  poke st,0,値  /  値 = peek(st,0)
; Associativity : BYTE (+1, 1byte)  poke st,1,値  /  値 = peek(st,1)
; LineSize : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; CacheSize : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; Type : PROCESSOR_CACHE_TYPE (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; Reserved : BYTE (+12, 18byte)  varptr(st)+12 を基点に操作(18byte:入れ子/配列)
; GroupCount : WORD (+30, 2byte)  wpoke st,30,値  /  値 = wpeek(st,30)
; Anonymous : _Anonymous_e__Union (+32, 16byte)  varptr(st)+32 を基点に操作(16byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global CACHE_RELATIONSHIP
    #field byte Level
    #field byte Associativity
    #field short LineSize
    #field int CacheSize
    #field int Type
    #field byte Reserved 18
    #field short GroupCount
    #field byte Anonymous 16
#endstruct

stdim st, CACHE_RELATIONSHIP        ; NSTRUCT 変数を確保
st->Level = 100
mes "Level=" + st->Level
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。