From: us on 22 Jul 2010 14:19 "Jose " > ok, guys, I understood...for default, when i am writing in my matlab > v=5...is the same as v=uint64(5)...it means 1 integer correspond to 8 bytes (64 bits). > > Cheers guys. no... v=5; % <- the equivalent of... w=double(5); % <- ...the def ML data type... us
From: Walter Roberson on 22 Jul 2010 14:59
Jose wrote: > Walter Roberson <roberson(a)hushmail.com> wrote in message > <i2a0ua$8m3$1(a)canopus.cc.umanitoba.ca>... >> Jose wrote: >> > Hello to everyone, why when i have to send 1 integer, i.e the number >> 5, > i have to send 4 bytes...i.e...why 1 integer correspond with 4 >> bytes, > and not 1 byte > ok, guys, I understood...for default, when i am writing in my matlab > v=5...is the same as v=uint64(5)...it means 1 integer correspond to 8 > bytes (64 bits). If Matlab automatically used the least storage needed for a value, what would you expect it to do in the case v = 5; v(2) = 99999; If you expect that this kind of minimal storage should only happen for scalar variables and that all non-scalar arrays should automatically be extended to the more general size, then what would you expect it to do in the case of v = int8(5); v(2) = 99999; Would you expect it to keep an internal flag for scalars about whether the type had been set explicitly or according the the range? Would you expect Matlab to continually adjust the storage size for a variable that is being changed in a loop? for K = 1:10000 v = mod(K^43 + 17*K + 5, 2^32); end some of those v values will be in the range 0 to 255 and some of them will be 256 to 65535 and some of them will be larger: should Matlab change the variable size each time? If you expect it to do that, then what is your expectation on how Matlab should do so and yet produce machine efficient code? CPUs take different amounts of time to work with different sizes; it is not uncommon for either 32 bit or 64 bit integers to be the fastest integers and it is common on modern computers for 8 bit integers to be the slowest of the integer accesses. |