5
I am making a game of navinha in C, and therefore need to put in a vector a large amount of projectiles.
These projectiles have at least one position and speed to make calculations, and I’m trying to decide how best to store them in memory for later use.
So there are some questions:
What is the fastest C language type for calculations on modern processors? Which faster type causes less mess in the alignment of a structure and wastes less memory?
This includes variations of types (not int vs float, but also int8_t, uint_fast32_t, double, long double, etc...)
A basic question: Do you really know why you want to optimize this? It seems to me that you are trying to make a premature and unnecessary optimization.
– Victor Stafusa
Because I want... boring people, in the OS in English also this persecution. I asked because I’m curious, I saw the new types of C99, and I thought it was cool, and I wanted to learn, I’m not a beginner, but I haven’t used C for many years, and I wanted to exercise my knowledge and learn more about the limits and dark corners of language. I think most C programmers don’t even know that a Struct can be greater than the sum of its members for example.
– speeder
Is your goal (a) to learn the darkest points of the C language, (b) to perform as well as possible in your game, or (c) to have the memory organization with as little mess as possible? In general, these three things are incompatible with each other and optimizing any of them will likely entail sacrificing the other two.
– Victor Stafusa
I don’t see why learning how to reach point (b), or (c) is opposite to point (a). (but I can see how (b) and (c) can be opposites)
– speeder
The question from @Victor is pertinent and doesn’t sound like stalking. It could save you a few hours or days by not doing an "unnecessary optimization". " Because I want to" is not a rational and objective decision of design. You can’t blame a user who wants to help you just because you mistook it for your question. :)
– user568459
Francisco Junior is that every time I ask performance questions, people drop the premature optimization thing, and they don’t answer. Actually in the English OS (where I asked the same question, and it became flamewar, with people wanting to delete or not the question based on the usefulness of optimization, instead of answering the question) I even asked to delete the question, I will no longer bring exoteric doubts to the OS, I’ll search for myself, and get the answer for myself, the people are very boring and rude.
– speeder
No one is being rude. @Victor was polite and asked a common question. He just wanted to help. Premature optimization is really a problem, whether you ignore it or not. And if your question caused trouble in the English OS, why didn’t you modify it to post here to avoid the risk of causing the same problem?
– user568459
I posted there, and soon after here, flamewar came after (at the same time that the Victor posted his comment). My nagging is not with Victor personally, I even understand why he asks, but with the whole situation. In the OS in English had moderator and users of very high karma arguing (type, people with more than 100,000 points)
– speeder