[Bf-python] a remark concerning functions returning lists
Willian Padovani Germano
wgermano at ig.com.br
Wed Jun 18 20:12:32 CEST 2003
On Wed, 2003-06-18 at 15:03, Jacques Guignot wrote:
> I saw that many functions returning a list follow this scheme :
>
> 1) Create a list of appropriate size
> 2) insert items in this list
> 3) return the list.
This is the "C" way, Guignot. It is faster and memory friendly, since
the list doesn't need to be freed and reallocated whenever you insert a
new item. It's very important to keep memory and speed issues in mind,
since these things accumulate and end up giving us a fat, slow
implementation. Remember that some scripts might create / deal with *a
lot* of objects.
> I think this procedure should be replaced by a simpler one :
>
> 1) Create an empty list
> 2) append the elements
> 3) return the list
This is Python way, where it's natural to favor code simplicity against
raw speed / nice memory handling. The more conscious we are in C, the
less script writers will need to be in BPython ; ).
--
Willian, wgermano at ig.com.br
More information about the Bf-python
mailing list