Jump to content
  • Advertisement
Sign in to follow this  
CProgrammer

arrays and points

This topic is 3989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm asking this question specifically regarding php. When using an array of points I came to thinking what the best approach would be. Basically I could use an array of ints and index them by multiplying by the dimensionality of a single point. Or I could have a Point class and then have an array of such points. Now what would be better in terms of performance. Having the array approach means that all memory is likely to be alligned in RAM, giving better caching. Also php doesnt have to follow a reference for each point and the garbage collector doesnt have to work with potentially hundreds of points. However when accessing points it is easier and more efficient to return a reference to the point then to create a temporary array. The point approach also saves the multiplication and addition required to access the points elements. Any thoughts? -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
I don't know what's better in terms of performance or RAM usage, but it shouldn't be too hard to run a few tests with some large datasets.

However, how important is performance and RAM usage compared to maintainability in this case? Did you verify that this really is a critical piece of code? Aren't there any higher-level optimizations you can think of that will gain you more? In other words, is this worth your time? :)

Share this post


Link to post
Share on other sites
Offcourse this is microoptimization and not all too relevant but I was still curious what others thought. I do however think it is somewhat more relevant in a php app since the script is executed many times, by each client. Even if it is just slightly slower and uses slightly more ram it will still add up when the amount of users grows. Also since php isnt compiled, defining an additional class means loading an additional file everytime. Offcourse maintainability outweighs the performance gain, however theere isnt too big of a design difference here. All the calculations are performed inside a single class, which exports individual points. Whether these are a class instance or an n-d array isnt too big of a difference here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!