NAME

Dyn::Call::Pointer - dyncall variant pointer

SYNOPSIS

use Dyn::Call qw[:memory];
my $ptr = malloc( 10 ); # <--- This is a Dyn::Call::Pointer
memmove( $ptr, 'Hello, world', 12 );
free( $ptr );

DESCRIPTION

It's a void pointer. Make whatever you want with it.

Functions

Most Dyn::Call::Pointer objects will be generated by dyncall and used internally but you may use malloc( ... ) or calloc( ... ) to create one for your own use.

malloc( $size )

Allocates $size bytes of uninitialized storage.

my $value1 = malloc( 10 ); # space for 10 bytes

On success, a new Dyn::Call::Pointer object is returned. To avoid a memory leaks, the returned pointer must be deallocated with free( ... ) or realloc( ... ).

Failure results in undef.

calloc( $num, $size )

Allocates memory for an array of $num objects of $size and initializes all bytes in the allocated storage to zero.

my $value2 = calloc( 50, 1 ); # space for 50 chars

On success, a new Dyn::Call::Pointer object is returned. To avoid a memory leaks, the returned pointer must be deallocated with free( ... ) or realloc( ... ).

Failure results in undef.

realloc( $ptr, $new_size )

Reallocates the given area of memory. It must be previously allocated by malloc( ... ), calloc( ... ) or realloc( ... ) and not yet freed with a call to free( ... ) or realloc( ... ).

my $value3 = realloc( $value2, 1024 );

On success, a new Dyn::Call::Pointer object is returned. To avoid a memory leaks, the returned pointer must be deallocated with free( ... ) or realloc( ... ).

Failure results in undef.

free( $ptr )

Deallocates the space previously allocated by malloc( ... ), calloc( ... ) or realloc( ... ).

free( $value2 );

memchr( $ptr, $ch, $count )

Finds the first occurrence of (unsigned char) $ch in the initial $count bytes (each interpreted as unsigned char) of the object pointed to by $ptr.

memcmp( $lhs, $rhs, $count )

Compares the first $count bytes of the objects pointed to by $lhs and $rhs. The comparison is done lexicographically.

Returns a negative value if $lhs appears before $rhs in lexicographical order.

Returns zero if $lhs and $rhs compare equal or if $count is zero.

Returns a positive value if $lhs appears after $rhs in lexicographical order.

memset( $dest, $ch, $count )

Copies the value (unsigned char) $ch into each of the first $count characters of the object pointed to by $dest.

memset( $ptr, 'a', 5 );

Returns a copy of $dest.

memcpy( $dest, $src, $count )

Copies $count characters from the object pointed to by $src to the object pointed to by $dest. Both objects are interpreted as arrays of unsigned char.

Returns a copy of $dest.

memmove( $dest, $src, $count )

Copies $count characters from the object pointed to by $src to the object pointed to by $dest. Both objects are interpreted as arrays of unsigned char. The objects may overlap: copying takes place as if the characters were copied to a temporary character array and then the characters were copied from the array to $dest.

Returns a copy of $dest.

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.

AUTHOR

Sanko Robinson <sanko@cpan.org>