Bug in STRMID system routine [message #82476] |
Thu, 13 December 2012 11:26 |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
Hi all,
strmid needs a bug fix. When I start with a very long string
a=string(byte(randomu(seed,1024^2*10)*(127.-32.))+32b)
and then extract a short substring
b=strmid(a,1,2)
the result b needs 10 MB of memory. As much as the original string a.
This overhead of memory can be released by a statement like b=b[0] or
b=b+''. However this is only a workaround and should be fixed in the
system routine itself.
A demo is attached below.
!version={x86 Win32 Windows Microsoft Windows 8.0.1 Oct 5 2010 32 64}
Cheers, Heinz
pro strmid_demo
compile_opt defint32,strictarr,logical_predicate
print,form='(%"\nStarting with:")'
help,/mem
a=string(byte(randomu(seed,1024^2*10)*(127.-32.))+32b)
print,form='(%"\nThe string needs about %d bytes:")',$
strtrim(strlen(a),2)
help,/mem
print,form='(%"\nA small substring needs the same amount of memory '+$
'as the original string:")'
b=strmid(a,1,2)
help,/mem
print,form='(%"\nThe memory can be released by a simple operation:")'
b+=''
help,/mem
print,form='(%"\nThe following is slow, but works:")'
p=ptrarr(1000,/alloc)
for i=0,n_elements(p)-1 do *p[i]=strmid(a,i,2)+''
help,/mem
print,form='(%"\n... and this probably runs into a memory '+$
'allocation error (if you don''t have tons of RAM):")'
for i=0,n_elements(p)-1 do *p[i]=strmid(a,i,2)
help,/mem
end
|
|
|