Hi, On Wednesday 30 Jun 2010 04:55:34 Yang Zhou wrote: > Hi all, > > I met a problem when I use Perl script to call a C function. A scalar > variable in Perl script is passed as an input parameter to the C function. > In the C function, it'll be used as a pointer, and the memory block it > points to will be used to store some data read from another structure. > Tests shows when memory block can't hold more than 24KB, if more than 24KB > is attempt to write to that memory block (pointed by the pointer in C, and > the scalar variable in Perl), a "segmentation fault" in the C function > occurs. > > I think there must be a limit for the size of a contiguous memory block > assigned to a perl scalar variable. The point is, how to assign a desired > size (e.g., 64KB) of memory block to the scalar variable in Perl? Like the > use of malloc in C?
First of all, this should probably be done in the Perl/XS level: http://perldoc.perl.org/perlxs.html Otherwise, you can use the x operator to allocate a block of data of the same character: << my $buffer = "\0" x (64 * 1024); >> Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ "Star Trek: We, the Living Dead" - http://shlom.in/st-wtld God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/