Hi Shlomi, Thanks for your help.
I tried the "my $buffer = "\0" x 65536; " method, but "segmentation fault" in the C function remains. I know little about "XS", it seems a declaration of the interface between Perl and C? Just a glimps of the link in your last mail, I can't find any Keyword which can be used to solve this problem. On Wed, Jun 30, 2010 at 10:38 AM, Shlomi Fish <shlo...@iglu.org.il> wrote: > 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 . > -- Best regards, Yang Zhou ------------------------------------------------------------------ Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein