On Mar 25, 2014, at 16:55 , Jens Alfke <j...@mooseyard.com> wrote:

> So if something is supposed to be a particular size (as seems to happen in 
> your app) declare it as a type of that size. If you don’t care about the size 
> and it won’t ever exceed a few billion, use `int` or `unsigned`. If it needs 
> to hold huge values, or if you want to be really conservative, use `SInt64` 
> or `UInt64`.

I'd recommend using the stdint types (int8_t, uint8_t, int16_t, uint16_t, 
int32_t, uint32_t, int64_t, uint64_t) when you want to be very specific about 
the size, rather than "int" or "unsigned," because those won't change size from 
one platform to another.

When dealing with structures on disk, I've created packed structs that exactly 
match the on-disk layout, then applied byte swapping before writing or after 
reading as appropriate. Then I just write or read the struct as a buffer. This 
gets a bit trickier for variable-size data, but works for the fixed-size 
portions of things.

Anyway, I would use something like that as a temporary mechanism to import the 
data into the app's new data structures, and generally I use 32-bit sizes for 
most storage of things (rarely do you need more, but if you have a lot and you 
know they're small, use a smaller int, but don't be too aggressive with that, 
especially if there's potential future need for more range).

-- 
Rick



Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to