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

Home » Public Forums » archive » Re: Push value onto an array?
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: Push value onto an array? [message #33680] Sat, 18 January 2003 18:12 Go to previous message
Ed Wright is currently offline  Ed Wright
Messages: 39
Registered: February 1999
Member
in article b07o36$24do$1@nntp6.u.washington.edu, Rick Towler at
rtowler@u.washington.edu wrote on 1/16/03 5:56 PM:

>
> "Ed Wright" wrote >
>> Question,
>>
>> How can I push a value onto an array?
>>
>> Given some array A of size m, how to add an entry at A[m]?
>>
>> Something like
>>
>> push @A, $value;
>>
>> This needs to be done in a loop. Yes, really.
>
> I think this was covered in depth a month or two ago. I just googled one
> entitled "How to use pointers instead of arrays" which covers some of the
> details (it quickly diverges from pointers and addresses your question
> directly).


Thanks,

I used Dr. Fanning's solution.


> In practice, this means that you have some kind of
> counter to tell you where you are in your array. If the
> counter gets above the "chunk" size, you allocate more
> memory to the array:
>
> array[counter] = value
> counter = counter + 1
> IF counter MOD 100 EQ 0 THEN array = [Temporary(array), Findgen(100)]
>
> When you finish adding things to your array, you trim
> it to the correct size:
>
> array = array[0:counter-1]
>
> This is both efficient and fast.

As always,
Ed Wright
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: How to plot with time as one axis ?
Next Topic: IDL 5.6, MacOSX, IDLWAVE, Xemacs, and suicide

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

Current Time: Fri Oct 10 14:42:50 PDT 2025

Total time taken to generate the page: 0.56094 seconds