Re: array operations and memory consumption [message #57943 is a reply to message #57942] |
Fri, 04 January 2008 15:16   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On Jan 4, 3:19 pm, dktr....@gmail.com wrote:
> Hi all,
>
> Apologies in advance if this is old hat ... I've got a question
> regarding IDL's memory usage that can be boiled down in the following
> example:
>
> IDL> a = BINDGEN(100,100,100)
> IDL> baseMem = (MEMORY())[0]
> IDL> a = a + 1
> IDL> PRINT, (MEMORY())[3] - baseMem
> 2000049
>
> I've tried modifying "a = a + 1" with various combinations of pointers
> and the TEMPORARY function, but can't reduce this temporary elevated
> memory consumption. Compare the above with a call to CONGRID:
>
> IDL> a = BINDGEN(100,100,100)
> IDL> baseMem = (MEMORY())[0]
> IDL> a = CONGRID(a, 100, 100, 100)
> IDL> PRINT, (MEMORY())[3] - baseMem
> 1003941
>
> I'm working with some very large image arrays and trying to do some
> "in place" manipulations. While I can slink by with the temporary
> memory usage of the latter CONGRID-type operations, addition (or
> multiplication) of an array by a scalar breaks the bank.
>
> Any tips or directions to a helpful tutorial on IDL's memory policies
> would be greatly appreciated. Thanks!
Be careful with type conversion here! In particular, 1 is a short
integer (or long integer depending on if compile_opt defint32 is
used), so a = a + 1 here converts a to type int. Consider the
following:
IDL> a = bindgen(100, 100, 100)
IDL> orig_mem = memory(/current)
IDL> a = a + 1
IDL> print, memory(/highwater) - orig_mem
2000082
IDL> a = bindgen(100, 100, 100)
IDL> orig_mem = memory(/current)
IDL> a = a + 1B
IDL> print, memory(/highwater) - orig_mem
1000096
IDL> a = bindgen(100, 100, 100)
IDL> orig_mem = memory(/current)
IDL> a = temporary(a) + 1B
IDL> print, memory(/highwater) - orig_mem
91
IDL>
IDL> a = bindgen(100, 100, 100)
IDL> orig_mem = memory(/current)
IDL> a += 1B
IDL> print, memory(/highwater) - orig_mem
91
IDL>
IDL> a = bindgen(100, 100, 100)
IDL> orig_mem = memory(/current)
IDL> a++
IDL> print, memory(/highwater) - orig_mem
91
Mike
--
www.michaelgalloy.com
Tech-X Corporation
Software Developer II
|
|
|