Dear all,
I have written a little R program to convert images. See below. Within the
loop over j (the filenames) memory consumption grows constantly. rm( ... )
inside the loop did not help. Memory does not grow if I remove the writeBin
statements between the two #-------- marks. But obviously this is not
solution I want...
Thanks for any advice.
Manfred Baumstark
P.S. As I'm new to R: what sort of tests can I make to trace the problem?
Configuration: R-gui 1.3.1, WinNT 4.0, the same happens in R under IRIX 6.5
--------------------------------------
# Read list of filenames made by ls -1 <exp> >filelist
cfn <- file("filelist", "rt")
fn <- readLines(cfn, n = -1, ok = TRUE)
close(cfn)
pad <- integer(length = 384)
for (j in 1:length(fn)) {
img <- file(fn[j], "rb")
header <- readChar(img,8192)
imv <- readBin(img, "integer", n=1536*1536, size=2, signed=FALSE,
endian="big")
close(img)
imm <- matrix(imv, nrow=1536, ncol=1536)
imout <- file(paste("test_", fn[j], sep=""),
"wb")
writeChar(header, imout, nchars = 512, eos = NULL)
#--------
for (i in 1:1536) {
writeBin(pad, imout, size=2, endian="big")
writeBin(imm[,i], imout, size=2, endian="big")
writeBin(pad, imout, size=2, endian="big")
}
#--------
close(imout)
rm( img, header, imv, imm, imout, i)
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: maba.vcf
Type: text/x-vcard
Size: 356 bytes
Desc: Card for Manfred W. Baumstark
Url :
https://stat.ethz.ch/pipermail/r-help/attachments/20011207/2ae484ae/maba.vcf
Dear all,
I have written a little R program to convert images. See below. Within the
loop over j (the filenames) memory consumption grows constantly. rm( ... )
inside the loop did not help. Memory does not grow if I remove the writeBin
statements between the two #-------- marks. But obviously this is not
solution I want...
Thanks for any advice.
Manfred Baumstark
P.S. As I'm new to R: what sort of tests can I make to trace the problem?
Configuration: R-gui 1.3.1, WinNT 4.0, the same happens in R under IRIX 6.5
--------------------------------------
# Read list of filenames made by ls -1 <exp> >filelist
cfn <- file("filelist", "rt")
fn <- readLines(cfn, n = -1, ok = TRUE)
close(cfn)
pad <- integer(length = 384)
for (j in 1:length(fn)) {
img <- file(fn[j], "rb")
header <- readChar(img,8192)
imv <- readBin(img, "integer", n=1536*1536, size=2, signed=FALSE,
endian="big")
close(img)
imm <- matrix(imv, nrow=1536, ncol=1536)
imout <- file(paste("test_", fn[j], sep=""),
"wb")
writeChar(header, imout, nchars = 512, eos = NULL)
#--------
for (i in 1:1536) {
writeBin(pad, imout, size=2, endian="big")
writeBin(imm[,i], imout, size=2, endian="big")
writeBin(pad, imout, size=2, endian="big")
}
#--------
close(imout)
rm( img, header, imv, imm, imout, i)
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: maba.vcf
Type: text/x-vcard
Size: 356 bytes
Desc: Card for Manfred W. Baumstark
Url :
https://stat.ethz.ch/pipermail/r-help/attachments/20011207/cfee6157/maba.vcf
Uwe Ligges asked me to produce a more simple example. Ok, the problem is as
follows: If I write big files memory utilization grows constantly. Here it
is a little test program, and it's output:
imv <- integer(length = 3000000)
memory.profile()
round(memory.size()/1048576.0, 2)
for (j in 1:20) {
imout <- file(paste("test", j, sep=""), "wb")
writeBin(1:2, imout, size=2, endian="big")
writeBin(imv, imout, size=2, endian="big") # this one makes the
problem
close(imout)
}
memory.profile()
round(memory.size()/1048576.0, 2)
Manfred
############ Write 20 big files> imv <- integer(length = 3000000)
>
> memory.profile()
NILSXP SYMSXP LISTSXP CLOSXP ENVSXP PROMSXP
LANGSXP
1 4080 104244 1280 4 0
53027
SPECIALSXP BUILTINSXP CHARSXP LGLSXP
INTSXP
59 483 10886 1510 0 0
24
REALSXP CPLXSXP STRSXP DOTSXP ANYSXP VECSXP
EXPRSXP
6693 4 6581 0 0 8
0
EXTPTRSXP
0 0 > round(memory.size()/1048576.0, 2)
[1] 20> for (j in 1:20) {
+
+ imout <- file(paste("test", j, sep=""),
"wb")
+ writeBin(1:2, imout, size=2, endian="big")
+ writeBin(imv, imout, size=2, endian="big") # this one makes the
problem
+ close(imout)
+ }> memory.profile()
NILSXP SYMSXP LISTSXP CLOSXP ENVSXP PROMSXP
LANGSXP
1 4081 104262 1280 4 0
53027
SPECIALSXP BUILTINSXP CHARSXP LGLSXP
INTSXP
59 483 10929 1510 0 0
26
REALSXP CPLXSXP STRSXP DOTSXP ANYSXP VECSXP
EXPRSXP
6693 4 6583 0 0 8
0
EXTPTRSXP
0 0 > round(memory.size()/1048576.0, 2)
[1] 134.44>
############ Write 20 small files> imv <- integer(length = 3000000)
>
> memory.profile()
NILSXP SYMSXP LISTSXP CLOSXP ENVSXP PROMSXP
LANGSXP
1 4080 104244 1280 4 0
53027
SPECIALSXP BUILTINSXP CHARSXP LGLSXP
INTSXP
59 483 10886 1510 0 0
24
REALSXP CPLXSXP STRSXP DOTSXP ANYSXP VECSXP
EXPRSXP
6693 4 6581 0 0 8
0
EXTPTRSXP
0 0 > round(memory.size()/1048576.0, 2)
[1] 20> for (j in 1:20) {
+
+ imout <- file(paste("test", j, sep=""),
"wb")
+ writeBin(1:2, imout, size=2, endian="big")
+ # writeBin(imv, imout, size=2, endian="big") # this one makes the
problem
+ close(imout)
+ }> memory.profile()
NILSXP SYMSXP LISTSXP CLOSXP ENVSXP PROMSXP
LANGSXP
1 4081 104261 1280 4 0
53027
SPECIALSXP BUILTINSXP CHARSXP LGLSXP
INTSXP
59 483 10909 1510 0 0
26
REALSXP CPLXSXP STRSXP DOTSXP ANYSXP VECSXP
EXPRSXP
6693 4 6583 0 0 8
0
EXTPTRSXP
0 0 > round(memory.size()/1048576.0, 2)
[1] 20>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: maba.vcf
Type: text/x-vcard
Size: 356 bytes
Desc: Card for Manfred W. Baumstark
Url :
https://stat.ethz.ch/pipermail/r-help/attachments/20011208/3307af36/maba.vcf