PHP 8.1.28 Released!

FFI::sizeof

(PHP 7 >= 7.4.0, PHP 8)

FFI::sizeofGets the size of C data or types

Beschreibung

public static FFI::sizeof(FFI\CData|FFI\CType &$ptr): int

Returns the size of the given FFI\CData or FFI\CType object.

Parameter-Liste

ptr

The handle of the C data or type.

Rückgabewerte

The size of the memory area pointed at by ptr.

add a note

User Contributed Notes 1 note

up
0
wowabbs+php at gmail dot com
3 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,
];
}
?>
To Top