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
.
+add a note
User Contributed Notes 1 note
wowabbs+php at gmail dot com ¶
4 years 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,
];
}
?>
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google