At 2003-08-21 00:54 +0200, Decapode Azur wrote: >> Or will PHP realize "OK I need to change the numbers indexing the other >> elements"? > >** as PHP is a high level language I can write very quickly and very easily >scripts to make manipulations on my 3D meshes, but the problem is that it >often takes more than an hour to execute, so I realy need to learn about >writing efficient code and optimizing PHP...
Perhaps you should have a look at the source code of the PHP-interpreter. I used to program in C and when I wanted to use flexible data structures like those in PHP I generally would use doubly linked lists and trees of them etc. (Meshes are much harder to maintain of course.) One can also use hash-tables. But some things can be fast given a certain implementation and others can be very slow. When you have an unusual problem (and you seem to have) then it's crucial to either control the mechanisms yourself or to know how PHP does it (but you shouldn't count on the fact that any internal mechanism will stay the same over time). As regards doubly linked lists (that I like a lot): You can travel through such a list in linear speed, but for example removing a couple of middle elements will cost in the order of n*0.5 iterations through the list (to find the first element to remove), so repeatly removing elements will be very expensive. Finding a single element in a doubly linked list can be sped up using a hash-code table, but it also makes things like renumbering numerically indexed entries a lot harder (I think, I never used a combination of these things.) But it's hard to estimate these things. Merging two already sorted linked lists into one takes linear time of course. I once even deviced a quick sort algorithm for doubly linked lists and was pleasently surprised that it was possible. (Qsort is of order n*log(n) unlike most sorting algorithms which are n*n). You may also want to consider writing some kind of underlying engine in C and then make it accessible from PHP for easy scripting. Most programs spend only 10-20% of their time in the fluffy code, which can therefore be written in a programmer-friendly language and 80-90% of their time in computationally intensive code that had better be optimized for speed. Years ago we would even hand-optimize the assembler output of the C-compiler to make the kernel of an application faster... Greetings, Jaap -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php