FFI::Raw::MemPtr - FFI::Raw memory pointer type
version 0.28
A FFI::Raw::MemPtr represents a memory pointer which can be passed to functions taking a FFI::Raw::ptr argument.
FFI::Raw::ptr
The allocated memory is automatically deallocated once the object is not in use anymore.
Allocate a new FFI::Raw::MemPtr of size $length bytes.
FFI::Raw::MemPtr
$length
Allocate a new FFI::Raw::MemPtr of size $length bytes and copy $buffer into it. This can be used, for example, to pass a pointer to a function that takes a C struct pointer, by using pack() or the Convert::Binary::C module to create the actual struct content.
$buffer
pack()
For example, consider the following C code
struct some_struct { int some_int; char some_str[]; }; extern void take_one_struct(struct some_struct *arg) { if (arg -> some_int == 42) puts(arg -> some_str); }
It can be called using FFI::Raw as follows:
use FFI::Raw; my $packed = pack('ix![p]p', 42, 'hello'); my $arg = FFI::Raw::MemPtr -> new_from_buf($packed, length $packed); my $take_one_struct = FFI::Raw -> new( $shared, 'take_one_struct', FFI::Raw::void, FFI::Raw::ptr ); $take_one_struct -> ($arg);
Which would print hello.
hello
Allocate a new FFI::Raw::MemPtr pointing to the $ptr, which can be either a FFI::Raw::MemPtr or a pointer returned by another function.
$ptr
This is the FFI::Raw equivalent of a pointer to a pointer.
FFI::Raw
Convert a FFI::Raw::MemPtr to a Perl string. If $length is not provided, the length of the string will be computed using strlen().
strlen()
Alessandro Ghedini <alexbio@cpan.org>
Copyright 2013 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install FFI::Raw, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FFI::Raw
CPAN shell
perl -MCPAN -e shell install FFI::Raw
For more information on module installation, please visit the detailed CPAN module installation guide.