e.g.
unsigned int vs unsigned short?
float vs double?
Are they necessary?
A fast, easy to use, free, and community supported 2D game engine
e.g.
unsigned int vs unsigned short?
float vs double?
Are they necessary?
I do it. But, I think it is over kill. There are so many more important things :)
I always stick to floats myself. Doubles have their place, but I haven't found one yet in any of my projects.
As for integer bit size and signing, I got in the habit of concerning myself with those kind of optimizations back when I was doing Nintendo DS development. But with iPhone I've gradually stopped. There are edge cases where it could definitely be justified, but otherwise its more trouble than it's worth. The iPhone doesn't have anywhere near the memory or processor limitations to justify it.
I remember having hard-to-find bugs from, for example, using an unsigned char to loop from 0 to 255. The result is an infinite loop, because 255 + 1 = 0 for the unsigned char type. The statement is always true (and the compiler would never give warnings for such things, which is also curious).
I optimize data types to "make sense". E.g. when I have a score value that should never be negative, I use an unsigned int. I don't optimize for memory footprint but I try to optimize for speed which led to the opposite of optimizing memory. I try to keep allocation cycles for objects as close to zero as possible. Some of my objects need paths of CGPoints. To avoid making path points single objects I just gave every object a path object which contains a static array of 200 CGPoints :D. Not the smartest solution if you plan on having insane amounts of objects, but it IS fast to access the points now :).
Is there a list of how much memory the data types consume so that I can calculate how much memory I'm actually wasting with this?
Does anyone know how much memory an empty CCArray consumes?
Because I am programming way more in C++ than in Objective-C I always catch me using parts of STL. But having some bytes consumed or not is not important for me. If there's a memory leak you should care about. Not a datatype that may take 32 byte more memory than another one.
Does anyone know how much memory an empty CCArray consumes?
I can't tell because I can't get the actual element out of the pointer. The pointer itself is 4 bytes big. You could find it out with the help of Instruments.
Thanks for the quick reply! I will try that tomorrow on some data types :).
IIRC, CCArray is an Objective-C wrapper for C-arrays, so it's like an NSArray but faster because it doesn't have as many checks in it (i.e. you have to make sure there aren't any issues)
I don't know, doesn't CCArray follow another concept of storing the items? I have some very vague memories of seeing people talk about a list approach versus something different.
That sizeof command was useful for getting the size of my array btw. I assume it gives the size of the datatype in byte (4 for float) and that would mean that my array of 400 CGPoint values is 400 x 2 x 4 byte = 3200 byte big. That's probably a lot for just floats but compared to textures its not thaaat much ;).
Still don't know how big the CCArray is since the sizeof seems to return the size of the pointer in memory only. I'll have to check with instruments some time.
CCArray is an Objective-C wrapper for C-arrays
That's not correct. CCArray actually allocates memory for objects and inserts/appends object in the allocated space. It does not act like a wrapper for std::vector.
sizeof is good, old, plain C. It gives you the size of the datatype you ask for. So a pointer on 32bit system is 4byte. A float depends on what it is IEEE or something else.
There seems to be some confusion about CCArray, it's just a wrapper around ccCarray, which is defined as
typedef struct ccArray {
NSUInteger num, max;
id *arr;
} ccArray;
So it's a array of pointers plus 2 NSUIntegers. It doesn't allocate space for the objects at all, only for the pointers.
Whoever is interested: After reading this conversation I actually created a class (CCArray2) that is a wrapper for the C++-array type std::vector. Most actions run 25% faster, the interface is almost the same. If you'd like to use it just add the two files to your project and use CCArray2 instead of CCArray. Download it by clicking here :)
Nahh. I like what araker made.
lol @birkemose, before creating more confusion ccCarray and CCArray are created by @manucorporat.
@paul, classes like this could become handy when cocos will go the c++ or obj-c++ way.
You must log in to post.