+ 3
Int vs long on 64bit machine
I know a long requires twice the memory. But do longs serve CPU performance benefits over int on 64bit machines ?
6 Antworten
+ 6
No. Generally long and int are both 4 bytes in size on 64bit arch, but sizes of int vary from arch to arch. That's why we use sizeof(). A general rule is to use int generically and allow the compiler to decide how many bytes to use. If you need a guaranteed width, use fixed-width types.
+ 4
C++ standard dont define a specific width of data type but only a minimum size and an guaranted order but implementation is platform and compiler dependents
http://en.cppreference.com/w/cpp/language/types
+ 3
If you're sending data between server and client, and you want to try to save possible headaches, you have two options:
1. Use a higher level language and let the framework worry about implementation and caveats.
2. At least try to ensure no hassles with different archs. Use wrappers where possible and make especial use of the following info sheet:
http://en.cppreference.com/w/cpp/types/integer
Personally I'd go with option 1, but it's up to you. Bear in mind portability and interoperability in the future as new platforms emerge. This is where more abstracted languages shine.
+ 2
Im not an expert but i think that depends on context... On perfomance context i think that its better if your data will be word aligned (usually but not always int) but this can make worse on memory context more you cannot rely on fact that int size is word size... I think that you must setup your compiler to fit best on your system and use int but i repeat that im not an expert
+ 2
good conversation ~ ya any way you can bridge or use less bytes the better - and merging and or batching where you can... As I said good conversation.
+ 1
Thank you so far.
I am currently coding a dedicated server. Would you recommend using short instead of int when sending small numbers in bytearrays from server to client ?