Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 906625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:25:05+00:00 2026-05-15T16:25:05+00:00

All, I’ve been a Java developer for 10 years…when it comes to managing numerical

  • 0

All,

I’ve been a Java developer for 10 years…when it comes to managing numerical data, for the most part I’ve stuck with int and used double when I need some decimal precision. The reason is we pretty much have a large heap space to work with and exhausting it is pretty difficult for the most part…

I’m starting iPhone development (I do have some C Programming knowledge) and I’m wondering if I should start looking at using appropriate data types given that the device itself has less resources than your typical JavaEE app…

For instance, I have an object with some numeric attribute (we’ll call this attribute ‘state’). This attribute will only ever have values from maybe -10 to 10. Originally, I defined this attribute using an int, but now I’ve decided to use char. The reason is I don’t need that many bits to represent the values from -10 to 10…so char is the smallest I need. Unfortunately, when someone sees a char they may think character, but I’m treating it as a number. I’m concerned that I’ll probably introduce some confusion if I stick with char…

So given this code fragment:

-(void)doSomething:(char)value {
    state = value;
}

then invoking it such as:

[myObject doSomething:1];

My question is should I even be worried about optimizing the data types in this manner? Do I need to start checking for overflow and throw errors? Or is this perfectly good programming?

Thanks!

EDIT: I think I shouldn’t have used the name state in my question. I don’t particularly have an enumeration here as I perform calculations on this value and update the state as appropriate. It just happens to have a fixed range.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:25:06+00:00Added an answer on May 15, 2026 at 4:25 pm

    While this is perfectly acceptable, (its typically how I do it) unless there are more than one chars in a row, alignment issues will force the next variable to waste 1-3 bytes anyway, which could otherwise have been used for free by an int. I encourage you to investigate alignment, its rather straightforward but a little to verbose to explain + consequences here. At any rate, in order to avoid confusion (although I doubt there will be very much, but basically to each their own) you may want to use int8_t or which is typedef-ed to signed char anyway.

    EDIT: Something I forgot before: the malloc implementation on MacOS (also the basis of iOS) only returns chunks of memory 16 bytes or longer, rounding up. So If you’re object takes, say 15 bytes, you’re also wasting a byte, and if it takes 17 bytes, you’re wasting 15.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All of a sudden, Facebook sharing has stopped working on my site. It's been
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
All along I've been testing on an Android 2 version ported to x86 (which
All the code/commands below are part of a PHP script that processes images from
All, In Apple's sample code DateCell http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html the ivar pickerView is declared in MyTableViewController.h
All the interfaces in Java like Serializable, Cloneable, Observable etc are suffixed with -able.
All modern browsers include gzip routines for exchanging compressed data with servers. Can anyone
All, If I run a query like the following: $qry = Select wrong_column from
All, If I've go the following database fields/values: user_id field_name field_value 1 EventHour1 1
All -- I have these two methods in one of my classes: public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.