FFI::sizeof
(PHP 7 >= 7.4.0, PHP 8)
FFI::sizeof — Gets the size of C data or types
参数
-
ptr
-
The handle of the C data or type.
返回值
The size of the memory area pointed at by ptr
.

User Contributed Notes 1 note
wowabbs+php at gmail dot com ¶
1 year ago
<?php // Sample using sizeof
Function _Win_Ffi_GlobalMemoryStatus()
{
static $Kernel32, $a, $r;
$Kernel32??=FFI::cdef(<<<'IDL'
typedef struct _MemoryStatus {
uint32_t Length ;
uint32_t MemoryLoad ;
uint64_t TotalPhys ;
uint64_t AvailPhys ;
uint64_t TotalPageFile ;
uint64_t AvailPageFile ;
uint64_t TotalVirtual ;
uint64_t AvailVirtual ;
} MemoryStatus;
void GlobalMemoryStatus(MemoryStatus* buf);
IDL, 'Kernel32.dll');
$a??=$Kernel32->new('MemoryStatus');
$a->Length =$Kernel32::sizeof($Kernel32->type('MemoryStatus'));
$r??=FFI::addr($a);
$Kernel32->GlobalMemoryStatus($r);
return [
'Total' =>$a->TotalPhys,
'Free' =>$a->TotalPhys-$a->AvailPhys,
'Load' =>$a->MemoryLoad*0.01,
];
}
?>