我知道Perl使用基于引用计数的垃圾收集.当变量超出范围时,引用计数递减,如果REFcount变为0,则取消分配内存.但是当我追踪下面显示的一个小例子时,我无法找到解除分配的情况.
print "start..";
Run Code Online (Sandbox Code Playgroud)
sub func
{
my $length = 8*1024*1024;
my $array = [1..$length];
Run Code Online (Sandbox Code Playgroud)
}
func();
print "done..";
Run Code Online (Sandbox Code Playgroud)
在该示例中,当程序启动时,Perl.exe占用约3 MB的物理内存.在func()调用期间分配后,Perl.exe占用~370 MB内存.但是在func()调用之后,分配的内存应该被垃圾收集.为什么不这样做?
期待您的回复.
无法找到此代码中发生内存泄漏的位置.
基本上我想为C函数编写一个XS包装器,它返回一个二维数组.
C函数:
int CW_returnArray(double** arrayDouble, int* count)
{
int number = 10;
int index, index1;
for(index = 0; index < number; index++)
{
for(index1 = 0; index1 < 10000; index1++)
{
arrayDouble[index][index1] = 12.51;
}
count[index] = 10000;
}
return number;
}
array -> output param to hold the two dimensional array
count -> output param to hold the number of element in each 1D array
Run Code Online (Sandbox Code Playgroud)
XS包装器:
void
returnArray()
PPCODE:
{
/** variable declaration **/
double** array;
int i …
Run Code Online (Sandbox Code Playgroud) 问题很简单.
如何在SML中使用Index变量访问元组?
val index = 5;
val tuple1 = (1,2,3,4,5,6,7,8,9,10);
val correctValue = #index tuple1 ??
Run Code Online (Sandbox Code Playgroud)
我希望,有人可以帮忙.提前致谢!
使用RegisterWaitForSingleObject()
代替的优点/缺点是WaitForSingleObject()
什么?
我之所以知道:
RegisterWaitForSingleObject()
使用OS中已有的线程池WaitForSingleObject()
,自己的线程应该轮询事件.唯一的区别是轮询与自动事件?或者这些之间是否有相当大的性能优势?
在Eclipse中使用Perl EPIC调试器时,为什么执行不会在'do'模块的断点处停止,而是停在'require'模块?
script.pl
use strict;
#use sample; # <-- Execution stops at breakpoint in printMessage() of 'sample.pm'
#require sample; # <-- Execution stops at breakpoint in printMessage() of 'sample.pm'
#do 'sample.pm'; # <-- Execution DO NOT STOP at breakpoint in printMessage() of 'sample.pm'
sample::printMessage();
Run Code Online (Sandbox Code Playgroud)
sample.pm
package sample;
sub printMessage
{
print 'new message!';
}
1;
Run Code Online (Sandbox Code Playgroud) 我不是perl的新手,但我无法解决这个问题.
这是我的问题陈述:
我正在使用Activestate perl 5.12 32位.我希望一次在内存中保留一些32 x 8MB的双重数组.不幸的是,在这种情况下我得到了"内存不足"的错误.例如,下面的代码将导致内存不足.
my $aref1 = [(.25) x (8*1024*1024)];
my $aref2 = [(.25) x (8*1024*1024)];
my $aref3 = [(.25) x (8*1024*1024)];
my $aref4 = [(.25) x (8*1024*1024)];
my $aref5 = [(.25) x (8*1024*1024)];
my $aref6 = [(.25) x (8*1024*1024)];
my $aref7 = [(.25) x (8*1024*1024)];
my $aref8 = [(.25) x (8*1024*1024)];
my $aref9 = [(.25) x (8*1024*1024)];
my $aref10 = [(.25) x (8*1024*1024)];
Run Code Online (Sandbox Code Playgroud)
有没有办法有效地处理它?
注意:在任何情况下,都需要在任何执行时尽快访问数组(因为用户不能等待太久)
我试过的选项:
怀疑perl基础知识 use
它有点类似于我的其他问题Perl:同一文件中的两个包...
考虑一个perl脚本:
Script.pl
use INCLUDES;
Run Code Online (Sandbox Code Playgroud)
INCLUDES.pm
package INCLUDES;
use Exporter;
############# MY DOUBT STARTS HERE ###############
use Module1;
use Module2;
##################################################
our @ISA = qw(Exporter);
our @EXPORT = qw();
sub import {
print 'INCLUDES imported to ' . caller . "\n";
}
Run Code Online (Sandbox Code Playgroud)
Module1.pm
package Module1;
use strict;
use Exporter;
use INCLUDES; #####=> INCLUDES.pm 'use'd
our @ISA = qw(Exporter);
our @EXPORT = qw();
1;
Run Code Online (Sandbox Code Playgroud)
Module2.pm
package Module2;
use strict;
use Exporter;
use INCLUDES; #####=> INCLUDES.pm 'use'd
our @ISA …
Run Code Online (Sandbox Code Playgroud) 这个问题可能看起来很简单,但过去几天我在考虑这个问题,我找不到答案.
我有多级脚本架构(代码如下所示)
CallingScript.pl(包含toplevel库并检查编译器错误)
do "IncludesConsumer.pm";
print "\n callingScript error : $@" if($@ || $!);
do "IncludesConsumer.pm";
print "\n callingScript error : $@" if($@);
do "IncludesConsumer.pm";
print "\n callingScript error : $@" if($@);
Run Code Online (Sandbox Code Playgroud)
IncludesConsumer.pm(添加库INCLUDES.pm并具有自己的功能)
do "INCLUDES.pm";
print "\nin IncludesConsumer";
Run Code Online (Sandbox Code Playgroud)
INCLUDES.pm(一个地方有多个模块,充当库)
use Module;
print "\n in includes";
Run Code Online (Sandbox Code Playgroud)
Module.pm(语法错误)
use strict;
sub MakeSyntaxError
{
print "\nerror in Module
}
1;
Run Code Online (Sandbox Code Playgroud)
在概念上,一旦核心模块(例如Module.pm)可能包含语法错误.所以我需要在CallingScript.pl中捕获它们.即:我想捕获文件中的Module.pm
(低级)语法错误CallingScript.pl
.
OUTPUT:
D:\Do_analysis>CallingScript.pl
in IncludesConsumer
in IncludesConsumer
in IncludesConsumer
Run Code Online (Sandbox Code Playgroud)
为什么编译器错误没有被CallingScript.pl捕获?请倾注你的想法.
谢谢!
perl ×6
perl-module ×2
c ×1
debugging ×1
eclipse ×1
epic ×1
memory-leaks ×1
package ×1
perl-xs ×1
sml ×1
tuples ×1
visual-c++ ×1
winapi ×1
windows ×1
xs ×1