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

Home » Public Forums » archive » Re: Modifying an array while conserving memory
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Modifying an array while conserving memory [message #30872 is a reply to message #30871] Fri, 24 May 2002 02:06 Go to previous messageGo to previous message
Randall Skelton is currently offline  Randall Skelton
Messages: 169
Registered: October 2000
Senior Member
> Why not using pointer:
>
> ptr1 = PTR_NEW(FINDGEN(1000))
> insert = PTR_NEW(RANDOMU(seed,100))
> a = PTR_NEW([(*ptr1)[0:499], (*insert), (*ptr1)[500:*]])
>
>
> HELP,*a

The problem with using pointers as above is that you are not actually
using the pointer, but copying the data contained within. Take a look at
the heap after doing the above:

IDL> help, /heap
Heap Variables:
# Pointer: 3
# Object : 0

<PtrHeapVar1> FLOAT = Array[1000]
<PtrHeapVar2> FLOAT = Array[100]
<PtrHeapVar3> FLOAT = Array[1100]

This shows that until I physically free the pointers 'ptr1' and 'insert',
I have used exactly double the memory as I now have a copy of each
variable.

Rather than inserting the data into the middle, I would (at this point) be
happy enough just concatenating to arrays...

IDL> ptr1 = PTR_NEW(FINDGEN(1000))
IDL> ptr2 = PTR_NEW(RANDOMU(seed,100))
IDL> a = [ptr1,ptr2]
IDL> print, *a ; fails
IDL> print, *(a) ; fails
IDL> print, *a(*) ; fails
IDL> print, *a[0] ; prints findgen(1000) (i.e. not what I want)
IDL> print, *(a)(*) ; fails... Score: IDL 5 ; Randall 0

Because IDL doesn't keep track of what type of data is in a pointer, the
above is protecting me from doing silly things:

IDL> ptr1 = PTR_NEW(FINDGEN(1000))
IDL> insert = ptr_new('test')
IDL> a = [ptr1, insert]

Perhaps this is something for dlm's. If I pass 'ptr1', 'insert' and the
indices for insertion into C I may be able to resize using 'ptr1' realloc,
shift the data around using pointers and trick the IDL variable structure
when sending the data back. This sounds risky but at this point all my
alternatives read, '% Unable to allocate memory: to make array'.

Cheers,
Randall
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: library help -- multiple procedures in one file
Next Topic: Modifying an array while conserving memory

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

Current Time: Sun Oct 12 05:11:58 PDT 2025

Total time taken to generate the page: 2.00045 seconds