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 #74170 is a reply to message #74169] Tue, 04 January 2011 14:30 Go to previous messageGo to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
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]
[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: Fri Oct 10 08:57:37 PDT 2025

Total time taken to generate the page: 0.63774 seconds