c++ - Redefine primitive types for quick change of RAM usage, better readability, (and possibly improving performance) -


after quite long time of spending in multiple programs have found that, depending on platform, need lower ram usage drastically, because of highly limited resources on platforms. store large maps , matrices in terms of these types, switching int32 int16 or float double (in case of different size) reduces usage half. thus, have added redefinitions such:

typedef double float; typedef int32_t int; typedef uint32_t uint; 

this allows me adjust important primitive types in program. note none of integers in program exceed size of 2 byte integer, there no issue using of int16 int64.

additionally, seems bit more readable have nice "int" there instead of "uint32_t". , in cases have observed change in performance both reducing size of primitive types , increasing it.

my question is: there disadvantages miss? couldn't find topic on yet, please lead me there if have missed well. code me, others might see it, in every case given me or proper documentation.

edit: sorry past mistake, indeed use typedefs.

typedef int32_t int; not bad, typedef double float; not good. because it's confusing: float is, in fact, double!?

why not use preprocessor define 2 sets of types, 1 large types, , 1 small types.

#ifdef large typedef int32_t int; typedef double real; #else typedef int16_t int; typedef float real; #endif void f() {     cout << sizeof(int) << endl;     cout << sizeof(real) << endl; } 

to use large types: g++ -o test test.cpp -dlarge

to use small types: g++ -o test test.cpp


Comments