05 Jul 2022 11:45:12 UTC
- Development release
- Distribution: FFI-Platypus
- Module version: 1.91_01
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (14)
- Testers (352 / 8 / 0)
- KwaliteeBus factor: 1
- 71.70% Coverage
- License: perl_5
- Perl: v5.8.4
- Download (384.57KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:21 non-PAUSE users
- Bakkiaraj Murugesan (bakkiaraj)
- Dylan Cali (calid)
- Zaki Mughal (zmughal)
- Fitz Elliott (felliott)
- Vickenty Fesunov (vyf)
- Gregor Herrmann (gregoa)
- Shlomi Fish (shlomif)
- Damyan Ivanov
- Ilya Pavlov (Ilya33)
- Petr Písař (ppisar)
- Mohammad S Anwar (MANWAR)
- Håkon Hægland (hakonhagland, HAKONH)
- Meredith (merrilymeredith, MHOWARD)
- Diab Jerius (DJERIUS)
- Eric Brine (IKEGAMI)
- José Joaquín Atria (JJATRIA)
- Pete Houston (openstrike, HOUSTON)
- SEE ALSO
- COPYRIGHT AND LICENSE
FFI::Platypus::Memory - Memory functions for FFI
use FFI::Platypus::Memory; # allocate 64 bytes of memory using the # libc malloc function. my $pointer = malloc 64; # use that memory wisely ... # free the memory when you are done. free $pointer;
This module provides an interface to common memory functions provided by the standard C library. They may be useful when constructing interfaces to C libraries with FFI. It works mostly with the
opaquetype and it is worth reviewing the section on opaque pointers in FFI::Platypus::Type.
my $pointer = calloc $count, $size;
callocfunction contiguously allocates enough space for $count objects that are $size bytes of memory each.
freefunction frees the memory allocated by
strdup. It is important to only free memory that you yourself have allocated. A good way to crash your program is to try and free a pointer that some C library has returned to you.
my $pointer = malloc $size;
mallocfunction allocates $size bytes of memory.
memcpy $dst_pointer, $src_pointer, $size;
memcpyfunction copies $size bytes from $src_pointer to $dst_pointer. It also returns $dst_pointer.
memset $buffer, $value, $length;
memsetfunction writes $length bytes of $value to the address specified by $buffer.
my $new_pointer = realloc $old_pointer, $size;
reallocfunction reallocates enough memory to fit $size bytes. It copies the existing data and frees $old_pointer.
If you pass
undefin as $old_pointer, then it behaves exactly like
my $pointer = realloc undef, 64; # same as malloc 64
strcpy $opaque, $string;
Copies the string to the memory location pointed to by
my $pointer = strdup $string;
strdupfunction allocates enough memory to contain $string and then copies it to that newly allocated memory. This version of
strdupreturns an opaque pointer type, not a string type. This may seem a little strange, but returning a string type would not be very useful in Perl.
my $pointer = strndup $string, $max;
The same as
strdupabove, except at most
$maxcharacters will be copied in the new string.
Main Platypus documentation.
Author: Graham Ollis <email@example.com>
Bakkiaraj Murugesan (bakkiaraj)
Dylan Cali (calid)
Zaki Mughal (zmughal)
Fitz Elliott (felliott)
Vickenty Fesunov (vyf)
Gregor Herrmann (gregoa)
Shlomi Fish (shlomif)
Ilya Pavlov (Ilya33)
Petr Písař (ppisar)
Mohammad S Anwar (MANWAR)
Håkon Hægland (hakonhagland, HAKONH)
Meredith (merrilymeredith, MHOWARD)
Diab Jerius (DJERIUS)
Eric Brine (IKEGAMI)
José Joaquín Atria (JJATRIA)
Pete Houston (openstrike, HOUSTON)
This software is copyright (c) 2015-2022 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install FFI::Platypus, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install FFI::Platypus
For more information on module installation, please visit the detailed CPAN module installation guide.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|