1FFI::Platypus::Memory(3U)ser Contributed Perl DocumentatiFoFnI::Platypus::Memory(3)
2
3
4

NAME

6       FFI::Platypus::Memory - Memory functions for FFI
7

VERSION

9       version 0.94
10

SYNOPSIS

12        use FFI::Platypus::Memory;
13
14        # allocate 64 bytes of memory using the
15        # libc malloc function.
16        my $pointer = malloc 64;
17
18        # use that memory wisely
19        ...
20
21        # free the memory when you are done.
22        free $pointer;
23

DESCRIPTION

25       This module provides an interface to common memory functions provided
26       by the standard C library.  They may be useful when constructing
27       interfaces to C libraries with FFI.  It works mostly with the "opaque"
28       type and it is worth reviewing the section on opaque pointers in
29       FFI::Platypus::Type.
30

FUNCTIONS

32   calloc
33        my $pointer = calloc $count, $size;
34
35       The "calloc" function contiguously allocates enough space for $count
36       objects that are $size bytes of memory each.
37
38   free
39        free $pointer;
40
41       The "free" function frees the memory allocated by "malloc", "calloc",
42       "realloc" or "strdup".  It is important to only free memory that you
43       yourself have allocated.  A good way to crash your program is to try
44       and free a pointer that some C library has returned to you.
45
46   malloc
47        my $pointer = malloc $size;
48
49       The "malloc" function allocates $size bytes of memory.
50
51   memcpy
52        memcpy $dst_pointer, $src_pointer, $size;
53
54       The "memcpy" function copies $size bytes from $src_pointer to
55       $dst_pointer.  It also returns $dst_pointer.
56
57   memset
58        memset $buffer, $value, $length;
59
60       The "memset" function writes $length bytes of $value to the address
61       specified by $buffer.
62
63   realloc
64        my $new_pointer = realloc $old_pointer, $size;
65
66       The "realloc" function reallocates enough memory to fit $size bytes.
67       It copies the existing data and frees $old_pointer.
68
69       If you pass "undef" in as $old_pointer, then it behaves exactly like
70       "malloc":
71
72        my $pointer = realloc undef, 64; # same as malloc 64
73
74   strdup
75        my $pointer = strdup $string;
76
77       The "strdup" function allocates enough memory to contain $string and
78       then copies it to that newly allocated memory.  This version of
79       "strdup" returns an opaque pointer type, not a string type.  This may
80       seem a little strange, but returning a string type would not be very
81       useful in Perl.
82
83   strndup
84        my $pointer = strndup $string, $max;
85
86       The same as "strdup" above, except at most $max characters will be
87       copied in the new string.
88

SEE ALSO

90       FFI::Platypus
91           Main Platypus documentation.
92

AUTHOR

94       Author: Graham Ollis <plicease@cpan.org>
95
96       Contributors:
97
98       Bakkiaraj Murugesan (bakkiaraj)
99
100       Dylan Cali (calid)
101
102       pipcet
103
104       Zaki Mughal (zmughal)
105
106       Fitz Elliott (felliott)
107
108       Vickenty Fesunov (vyf)
109
110       Gregor Herrmann (gregoa)
111
112       Shlomi Fish (shlomif)
113
114       Damyan Ivanov
115
116       Ilya Pavlov (Ilya33)
117
118       Petr Pisar (ppisar)
119
120       Mohammad S Anwar (MANWAR)
121
123       This software is copyright (c) 2015,2016,2017,2018,2019 by Graham
124       Ollis.
125
126       This is free software; you can redistribute it and/or modify it under
127       the same terms as the Perl 5 programming language system itself.
128
129
130
131perl v5.30.0                      2019-07-26          FFI::Platypus::Memory(3)
Impressum