i'm in the need of a 1 byte data type.
i don't want to use 'char'.
heck, theoretically, could i make a 4bit type? ... 2bit?
what are my options?
i'm in the need of a 1 byte data type.
i don't want to use 'char'.
heck, theoretically, could i make a 4bit type? ... 2bit?
what are my options?
Last edited by simpleid; 11-04-2007 at 08:19 PM.
Any class or struct you write creates a new datatype.
All new datatypes will be at least one byte.
Why don't you want to use char? If you want to keep your type separate from char you can wrap a class around a char. You can also use a typedef so your "type" has a different name, although in reality it will be the same type.
If you want to save space and only use 4 bits, you can't create a datatype to do it, but you might be able to use other storage options to get a similar effect.
You could use bit-fields, but those are nasty.
Just use unsigned char.
i don't want to do this, to store the value;
(unsigned char)( (short int) val )
i don't want to cast either, to just store a value in to an unnecessarily large data type.
on principle i'd like to make this as perfect as possible.
so if anyone else knows, tell me.
i'm going to look in to bit fields.
the code i'm writing requires three large arrays, when i initialize them with INT the app crashes. if i use the smallest necessary types it works fine.
at least until i scale the window large enough then it crashes anyway.
i have 2gb of memory and the usage never goes over 1gb, any explanations for that? i might be able to get around having to do this if i can figure that out.
Last edited by simpleid; 11-04-2007 at 08:40 PM.
or just char, since char is unsigned by default (whereas short, long, int, long long int/"the equivalent in microsoft world" are signed by default)
that suggests poor design.the code i'm writing requires three large arrays, when i initialize them with INT the app crashes. if i use the smallest necessary types it works fine.
at least until i scale the window large enough then it crashes anyway.
Can you post a bit more code so we know what are you trying to do?
alright, sure;
this is global;
this is in the render loop, but *only* executes if the window is scaled;Code:const int AW = 512, AH = 384; typedef struct RGB { unsigned char r, g, b; }; RGB Image[AW][AH];
Code:CW = glutGet(GLUT_WINDOW_WIDTH); CH = glutGet(GLUT_WINDOW_HEIGHT); RGB AImage[CW][AH]; RGB SImage[CW][CH];
if the RGB struct uses SHORT INT, merely initiating SImage crashes the app. (using unsigned char)
the app crashes anyway if the window is scaled beyond 800x600-ish.
Last edited by simpleid; 11-04-2007 at 09:07 PM.
>> char is unsigned by default
This isn't guaranteed. It depends on the implementation.
What range of values are possible for your numbers?
char is not unsigned by default on my machine.
i need to store values no larger than 255 for each of the three primary color components.
storing the three color components in to an int was unnecessary since it offered too much space.
just fyi in case anyone mentions it. and as i've said, too large of data types crashed my app.
I don't see how large data types can crash your app.
Even your "huge" array of RGB (even if you switch them out with ints instead of chars), would take about 2 MB of memory. Something else may be amiss.
800x600 * 4 bytes is still only about 1.92 MB, there should be plenty of heap space for that. It might cause you to run out of stack space. Perhaps you should use dynamic memory like a vector to hold the data.
never mind! i forgot to change a couple things. the app doesn't crash anymore.
thanks for the heads up on the vectors daved.
and i guess i'll stick with unsigned chars.
Last edited by simpleid; 11-04-2007 at 09:37 PM.
Edit: Apparently the problem was solved by the removal of the stack based arrays.
Last edited by Daved; 11-05-2007 at 02:45 AM.