FFI::Platypus::Legacy::Raw::MemPtr - FFI::Platypus::Legacy::Raw memory pointer type
version 0.05
FFI::Platypus::Legacy::Raw and friends are a fork of FFI::Raw that uses FFI::Platypus instead of FFI::Raw's own libffi implementation. It is intended for use when migrating from FFI::Raw to FFI::Platypus. The main reason one might have for switching from Raw to Platypus is because Platypus is actively maintained, provides a more powerful interface, can be much faster when functions are "attached", and works on more platforms than Raw. This module should be a drop in replacement for FFI::Raw, simply replace all instances of FFI::Raw to FFI::Platypus::Legacy::Raw. See also Alt::FFI::Raw::Platypus for a way to use this module without making any source code changes.
FFI::Raw
FFI::Platypus::Legacy::Raw
A FFI::Platypus::Legacy::Raw::MemPtr represents a memory pointer which can be passed to functions taking a FFI::Platypus::Legacy::Raw::ptr argument.
FFI::Platypus::Legacy::Raw::ptr
The allocated memory is automatically deallocated once the object is not in use anymore.
FFI::Platypus::Legacy::Raw::MemPtr->new( $length );
Allocate a new FFI::Platypus::Legacy::Raw::MemPtr of size $length bytes.
FFI::Platypus::Legacy::Raw::MemPtr
$length
my $memptr = FFI::Platypus::Legacy::Raw::MemPtr->new_from_buf( $buffer, $length );
Allocate a new FFI::Platypus::Legacy::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::Platypus::Legacy::Raw as follows:
use FFI::Platypus::Legacy::Raw; my $packed = pack('ix![p]p', 42, 'hello'); my $arg = FFI::Platypus::Legacy::Raw::MemPtr->new_from_buf($packed, length $packed); my $take_one_struct = FFI::Platypus::Legacy::Raw->new( $shared, 'take_one_struct', FFI::Platypus::Legacy::Raw::void, FFI::Platypus::Legacy::Raw::ptr ); $take_one_struct->($arg);
Which would print hello.
hello
my $memptr = FFI::Platypus::Legacy::Raw::MemPtr->new_from_ptr( $ptr );
Allocate a new FFI::Platypus::Legacy::Raw::MemPtr pointing to the $ptr, which can be either a FFI::Platypus::Legacy::Raw::MemPtr or a pointer returned by another function.
$ptr
This is the FFI::Platypus::Legacy::Raw equivalent of a pointer to a pointer.
my $memptr = FFI::Platypus::Legacy::Raw::MemPtr->to_perl_str; my $memptr = FFI::Platypus::Legacy::Raw::MemPtr->to_perl_str( $length );
Convert a FFI::Platypus::Legacy::Raw::MemPtr to a Perl string. If $length is not provided, the length of the string will be computed using strlen().
strlen()
Original author: Alessandro Ghedini (ghedo, ALEXBIO)
Current maintainer: Graham Ollis <plicease@cpan.org>
Contributors:
Bakkiaraj Murugesan (bakkiaraj)
Dylan Cali (CALID)
Brian Wightman (MidLifeXis, MLX)
David Steinbrunner (dsteinbrunner)
Olivier Mengué (DOLMEN)
This software is copyright (c) 2012 by Alessandro Ghedini.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install FFI::Platypus::Legacy::Raw, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FFI::Platypus::Legacy::Raw
CPAN shell
perl -MCPAN -e shell install FFI::Platypus::Legacy::Raw
For more information on module installation, please visit the detailed CPAN module installation guide.