27.05.2017, 14:39
Quote:
Store structured data, not strings - if you're just using it in the code.
If you want to store the most recent 32 damage events, simply make an array that's 32 cells of your structure and a "pointer" variable that stores a particular cell in that array. Each time a damage event gets logged, you increment that pointer value and when it hits 32 you set it to 0. This is pretty close to a circular-queue or ring-list. You don't need to re-order the data at all because your pointer always marks the end of the list. PHP Code:
|
I was going to suggest this method (not even kidding), but I initially thought of suggesting something simpler - reordering (not that performance friendly for large arrays) or a large string.
The large string would not require any reformatting, just deleting the first part and inserting a new entry at the end. I'm not sure if strdel and strins' execution time is determined by the total cells of a string like format, but for 32 damage logs, there won't be much of a problem.
What I would advise doing if you'd like to go with the large string method, is bench-marking strdel and strins on small strings and large strings. If their performance isn't strictly tied to the amount of cells rather to what you are inserting, then you'd be fine (though I would not recommend that you use this method if you're going to save the data to a database).