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

Home » Public Forums » archive » Re: More efficient method of appending to arrays when using pointers?
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: More efficient method of appending to arrays when using pointers? [message #74169 is a reply to message #74166] Tue, 04 January 2011 14:39 Go to previous messageGo to previous message
Matt Francis is currently offline  Matt Francis
Messages: 94
Registered: May 2010
Member
On Jan 5, 9:30 am, Gray <grayliketheco...@gmail.com> wrote:
> On Jan 4, 5:01 pm, Matt Francis <mattjamesfran...@gmail.com> wrote:
>
>
>
>> I have some code I've written that looks clunky and I was wondering if
>> there is a more efficient (faster and or using less memory) way to do
>> this.
>
>> I am using a custom object with a member self.foo which will end up
>> being a matrix, built up by appending arrays one at a time as I loop
>> over each step of a process. This update code currently looks like
>> this:
>
>> temp = [ *(self.foo),next_array]
>> ptr_free,self.foo
>> self.free = ptr_new(temp)
>
>> This seems to be a bit wastefull in terms of how many times memory is
>> allocated and deallocated to get the job done. Something simple like
>
>> self.free = ptr_new([*(self.foo),next_array]
>
>> causes a memory leak due to the dangling pointer. I don't see how the
>> TEMPORARY function can be used here without causing a leak.
>
>> Any tips from the pros?
>
> Why mess about with ptr_new and ptr_free?  Unnecessary.
>
> temp = [*self.foo,next_array]
> *self.foo = temp
>
> Or, the minimalist approach:
>
> *self.foo = [*self.foo,next_array]

Hmmm, I didn't expect that would work! Still keep forgetting IDL
'pointers' aren't really pointers and can do funny things (I'm a C++
programmer and this wouldn't work with a 'real' pointer).

Thanks for your help.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to extract a scalar from a vector?
Next Topic: Re: Associating GeoTiFF tags with basic Mercator projection parameters?

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

Current Time: Sat Oct 11 01:30:09 PDT 2025

Total time taken to generate the page: 0.32144 seconds