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

Home » Public Forums » archive » Array Subscripting Memory Usage (watch out!)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Array Subscripting Memory Usage (watch out!) [message #32328] Wed, 02 October 2002 14:28 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Hi all,

This may be old news to some of you, but it surprised me and a couple of
colleagues, and I couldn't find any discussion of it on this group, so
I'll share it around.

I was surprised to find how much memory is used during access to a
subset of an array. I ran this, which makes a 1000x1000 array, and
accesses a subset of it using an array of subscripts:

a = bindgen(1000, 1000)
subscripts = Long(RandomU(seed, 500)*1000)
baseMem = (memory())[0]
help, a[subscripts, *]
highWaterMem = (memory())[3]
Print, 'Memory used during access: ', highWaterMem-baseMem

IDL> .GO
<Expression> BYTE = Array[500, 1000]
Memory used during access: 2500076

The array being extracted is 0.5 million bytes, but it took 2.5 million
bytes to do it! I'm guessing that there's a Long array being made behind
the scenes that contains the indices of the elements I'm going to get
back.

This came to light when my client was using a couple of 100MB images on
a machine with 1GB of RAM, and my program ran out of memory! There are
other factors here, but it was unexpected that accessing N bytes from an
array requires 5*N bytes for the operation! I know now to be more
careful.

Hope this helps out someone else.

Cheers,
--
-Dick

Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Array comparison part 2
Next Topic: how to get time consumed by idl program?

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

Current Time: Wed Oct 08 15:51:51 PDT 2025

Total time taken to generate the page: 0.00401 seconds