Debian Codegraph @

examples/malloc.pl

raw
1 use strict;
2 use warnings;
3 use FFI::Platypus 2.00;
4 use FFI::Platypus::Memory qw( malloc free memcpy strdup );
5
6 my $ffi = FFI::Platypus->new( api => 2 );
7 my $buffer = malloc 14;
8 my $ptr_string = strdup("hello there!!\n");
9
10 memcpy $buffer, $ptr_string, 15;
11
12 print $ffi->cast('opaque' => 'string', $buffer);
13
14 free $ptr_string;
15 free $buffer;