0

I was reading this and I am curious about what was meant by increasing the memory footprint. I am not an expert in any of this, by any means. I actually know very little, other than what I've come up with thinking about how systems work. If someone could help clarify my thoughts and correct me where I'm wrong, I would really appreciate it.

I know that by using the proper typedefs, I am future-proofing my code in case apple changes the structure of the typedef and using typedefs shouldn't affect the processor, since its the compiler's or preprocessor's job to basically convert them. But will it actually use any more memory than is necessary, if the typedefs are only used for functions that expect them (and their precision), such as CGRect/CGSize/etc and NSDate functions that ask for those typedefs?

Basically, is there any EXTRA memory being used, given that they are only being used in situations where functions ask for them, rather than using their current counterparts (CGFloat -> float)?

This is for iOS vs OSX, since I know that OSX has both 32bit and 64bit processors and the typedefs are expected.

Community
  • 1
  • 1
RileyE
  • 10,874
  • 13
  • 63
  • 106

2 Answers2

1

Think of it this way. Memory footprint often means how much memory you are consuming at any time. If you without any reason use 64 bit values instead of perfectly useful 32 bit ones, then there is some marginal inflation. That said, I'll bet most of your usage is in automatics and object ivars.

On iOS now, CGFloat == float.

I personally ALWAY use CGFloat for anything that might interface with iOS - that is, unless I'm doing some math functions. And for exactly as you said. The other day I had to grab some code on iOS and move it to a Mac app, and it took almost not time (as I use CGFlat, NSInteger, and friends). You will get no conversion warnings (ie moving 64 bit values into 32 bit ones).

In the future, given the popularity of iOS, its quite likely that there will be processors using 64 bit floating point and integers. Its the nature of progress. If you use the CGFloat and friends, your code will compile without warnings on a universal app the does both 32 and 64 bit.

David H
  • 40,852
  • 12
  • 92
  • 138
  • So, basically, it doesn't do any harm, but rather provides transferability, so long as I'm conscious of where I'm using them (using float and double in my own functions, where they apply). Thanks! – RileyE Aug 09 '12 at 02:44
  • 1
    It only has the potential - and note that wordage - the POTENTIAL - for some slightly greater memory usage - if and ONLY if Apple releases devices with a 64bit runtime on them. And if it does that, it will have to provide much more memory on that device as their own frameworks will use more memory. – David H Aug 09 '12 at 12:18
  • Awesome. Thats what I thought, but I wanted to make sure. Thanks! You could probably help me with my latest question about properties, too! – RileyE Aug 11 '12 at 00:30
0

If Apple uses CGFloat, why would you be concerned about it? Use the types that match the api calls which you are calling. If CGFloat was a memory problem our phones would all be crashing.

deleted_user
  • 3,817
  • 1
  • 18
  • 27
  • The difference between thousands upon thousands of doubles vs floats is a big deal. Thats why I wanted to ask about it. Knowing is always a better solution than being oblivious. – RileyE Aug 11 '12 at 00:30