Is there a way to define a type of integers, that are only 7 bits long? Or at least 1 byte long? I want to replace standard integers stored in database to reduce the size. I am using mainly those databases: MySQL, Sparksee (for graphs). And those languages: C++, Objective-C++. Is using char
instead of int
- my best option?

- 424
- 1
- 6
- 17
1 Answers
MySQL supports the TINYINT
(8 bit), SMALLINT
(16 bit), MEDIUMINT
(24 bit), INT
(32 bit), and BIGINT
(64 bit) data types. http://dev.mysql.com/doc/refman/5.7/en/integer-types.html
The corresponding C language data types are int8_t
, int16_t
, int32_t
, and int64_t
. There isn't a standard 24-bit data type in C. See this for more information. http://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html
These are signed data types. So, for example, int8_t
has potential values in the range [-128, 127].
You will need a very large number of records in your system for your cost saving from using smaller integers to exceed one dollar US. SSD drives currently cost something less than $0.50 per gigabyte. Best to spend your time and effort elsewhere.

- 103,626
- 17
- 118
- 172
-
I have tens-hundreds of billions values, so this might be useful. Thanks for response. – ashvardanian Feb 02 '16 at 22:42
-
According to Sparksee docs, the smallest int size they support is 32 bits. Is it so or there is a hint? – ashvardanian Feb 02 '16 at 22:46