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 1.43
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   strcpy
75        strcpy $opaque, $string;
76
77       Copies the string to the memory location pointed to by $opaque.
78
79   strdup
80        my $pointer = strdup $string;
81
82       The "strdup" function allocates enough memory to contain $string and
83       then copies it to that newly allocated memory.  This version of
84       "strdup" returns an opaque pointer type, not a string type.  This may
85       seem a little strange, but returning a string type would not be very
86       useful in Perl.
87
88   strndup
89        my $pointer = strndup $string, $max;
90
91       The same as "strdup" above, except at most $max characters will be
92       copied in the new string.
93

SEE ALSO

95       FFI::Platypus
96           Main Platypus documentation.
97

AUTHOR

99       Author: Graham Ollis <plicease@cpan.org>
100
101       Contributors:
102
103       Bakkiaraj Murugesan (bakkiaraj)
104
105       Dylan Cali (calid)
106
107       pipcet
108
109       Zaki Mughal (zmughal)
110
111       Fitz Elliott (felliott)
112
113       Vickenty Fesunov (vyf)
114
115       Gregor Herrmann (gregoa)
116
117       Shlomi Fish (shlomif)
118
119       Damyan Ivanov
120
121       Ilya Pavlov (Ilya33)
122
123       Petr Pisar (ppisar)
124
125       Mohammad S Anwar (MANWAR)
126
127       Håkon Hægland (hakonhagland, HAKONH)
128
129       Meredith (merrilymeredith, MHOWARD)
130
131       Diab Jerius (DJERIUS)
132
133       Eric Brine (IKEGAMI)
134
135       szTheory
136
138       This software is copyright (c) 2015,2016,2017,2018,2019,2020 by Graham
139       Ollis.
140
141       This is free software; you can redistribute it and/or modify it under
142       the same terms as the Perl 5 programming language system itself.
143
144
145
146perl v5.32.1                      2021-03-18          FFI::Platypus::Memory(3)
Impressum