From: Eshbonzie on
Hey Guys,

Well I guess its a trivial question, however I really couldnt find an answer for it till now!

Im implementing an algorithm where memory is a critical issue as usual. Im working with an array of counters which are needed in the algorithm. The array size is 2^26 and each counter inside the array can never exceed 153000.

if I define the counter as

counterArray = zeros(2^26, 1, 'uint16')

it wont be enough as the maximum value would be 65536. So the only way would be to define it as

counterArray = zeros(2^26, 1, 'uint32')

but then I will never use 14 bits(32 bits-18 bits which I need to cover the 153000) out of the 32 bits.

Is there any way to define the variable size bitwise saving this 14 bits for each array cell? or even define the counter as three bytes isntead of four and save one byte for each cell?

Thanks,

Eshbon
From: us on
"Eshbonzie " <esbonzie(a)googlemail.com> wrote in message <i0uqog$4bi$1(a)fred.mathworks.com>...
> Hey Guys,
>
> Well I guess its a trivial question, however I really couldnt find an answer for it till now!
>
> Im implementing an algorithm where memory is a critical issue as usual. Im working with an array of counters which are needed in the algorithm. The array size is 2^26 and each counter inside the array can never exceed 153000.
>
> if I define the counter as
>
> counterArray = zeros(2^26, 1, 'uint16')
>
> it wont be enough as the maximum value would be 65536. So the only way would be to define it as
>
> counterArray = zeros(2^26, 1, 'uint32')
>
> but then I will never use 14 bits(32 bits-18 bits which I need to cover the 153000) out of the 32 bits.
>
> Is there any way to define the variable size bitwise saving this 14 bits for each array cell? or even define the counter as three bytes isntead of four and save one byte for each cell?
>
> Thanks,
>
> Eshbon

frankly - if your project really depends on such minute(!) memory tuning, it's very likely to fail anyhow given all the remaining stuff your OS/ML is doing in the background...

us
From: Eshbonzie on
Thank you both for your replies, but I still find it so weird that this is not an option :S!!

well...maybe it has to do with the memory allocation and addresses, thats why it is not an option.

Thanks again,

Eshbon!
 | 
Pages: 1
Prev: importdata problem
Next: greta