Die Flagge des Marasek

Dekostreifen

English

Aktuell Texte Der Comic Impressum Kalender Suche PHP-Klassen Container-Wizard main.s21

Kategorien

Buch
Computer
Computerspiele
Film
Geschichte
Gesellschaft
Idee
Kunst
Natur
Persönlich
Politik
Programmieren
Religion & Philosophie
Weblog
Weltpolitik
Weltsicht
{{login}}

Data Structures in PHP

Permalink
Vorheriger: What makes fanbois so bitter?Nächster: Die Moslems vor den Toren Europas!
Eingeordnet in: Programmieren

Another supplemental to Python vs. PHP. What was brought against PHP was that it didn't have "data structures you know from computer science", such as Heap, LinkedList, Hashmap and so on. Actually, Java does and it is a pain in the ... in most situations. People have attacked me for not knowing enough about data structures, otherwise I would know which to take. Well, that's not the point. The point is, that for many purposes, it is simply not important, when we're talking about putting three to five values in an array. PHP mostly exists in the web environment, and there time and memory is the most limiting factor which prohibits to deal with big arrays anyway. I doubt that with the sizes arrays can feasibly have within a PHP script, a difference will already appear.
Once, I did image computation with PHP, which was in the end demosaicing RAW files. I had written my own interpreter for PGM and ended up with a huge string representing 10 MP / 16 bytes per pixel. Putting that into an array would have helped me in terms of abstraction, but no way. PHP would fail on memory. So I had to work with the string, which took a loooong time. The whole script would run for a few minutes and then chew out an image file (it was a CLI script of course). It of course served no real purpose, as everything could be done with dcraw as well. But I for once wanted to do it myself.

I reimplemented the whole bunch with Java, because I wanted to have some additional effects. I expected Java to be somewhat faster, but actually, Java is fast enough for real time. Yes, real time, which is I can change a setting on a GUI and the preview will redraw me a picture with little lag involved. Of course, there I could use an array, no problem. So specific data structures have their purpose.

While going to work this morning, I thought about ArrayAccess, Iterator and Countable. These actually should enable people to implement specialized data structures and fork them out as PHP classes, which could then be treated as arrays. And so they did - with PHP 5.3, SPL comes along with some structures such as SPLHeap.

I tried SplFixedArray, yet couldn't make out any difference. Memory limit hit me first, and I didn't care to expand it. As I said, within the context of web applications or small CGI scripts, we're not talking about a real problem here.

Kommentieren

Bitte beachten: Kommentare sind nicht sofort sichtbar, sondern werden erst nach einer kurzen Prüfung freigegeben, sofern keine rechtliche Beanstandung vorliegt.
Rechtlich bedenkliche Inhalte werden entweder entschärft oder nicht veröffentlicht.

* Titel  
* Nickname  
* Kommentar