comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: array operations and memory consumption
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: array operations and memory consumption [message #57942] Fri, 04 January 2008 15:55
dktr.ted is currently offline  dktr.ted
Messages: 17
Registered: November 2006
Junior Member
Type conversion! That was what was missing from my understanding.
This makes much more sense now. Thanks for the pointers. I also had
forgotten the increment operator, although I was looking for something
more general.






-Ted

On Jan 4, 3:16 pm, "mgal...@gmail.com" <mgal...@gmail.com> wrote:
> 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
Re: array operations and memory consumption [message #57943 is a reply to message #57942] Fri, 04 January 2008 15:16 Go to previous message
Michael Galloy is currently offline  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
Re: array operations and memory consumption [message #57944 is a reply to message #57943] Fri, 04 January 2008 15:16 Go to previous message
don.woodraska is currently offline  don.woodraska
Messages: 13
Registered: October 2005
Junior 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

Consider using the increment operator like this:

IDL> a++

This does an increment in-place with little additional memory (a few
bytes). The assignment c-style operators like this one below, use
double the memory.

IDL> a += 1

I haven't seen MEMORY before. Is this new in 7.0? I use help,/memory
which doesn't behave like I expect.

Good luck,
Don
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: array operations and memory consumption
Next Topic: Re: read_ascii for many rows / possible to create automatic names for variables

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:12:32 PDT 2025

Total time taken to generate the page: 0.00766 seconds