By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Linearly Value Compressed Vector (Container)

P: n/a
Hey there, C++ Coders.

Does anyone know of a C++ (template) (vector) container that packs its
elements based on their relative minimum and maximum value (offset and
span) and (minimum) stride.

Example:
The pointers [ 0x00, 0x04, 0x12, 0x20 ] when packed should be stored
internally in the template<Tcontainer as
T min: 0
T stride: 4
packed values: [ 0, 1, 3, 5 ] (in this case be stored in a
std::vector<uint8_t>)

I think such a container would be especially suitable for storing
"small" arrays of pointers. Especially on a 64-bit architecture where
a pointer takes 8 bytes, this would reduce memory usage by up to 8
times. This example, of course, holds only for the ideal case where
the array has exactly 256 number of elements and these elements are
all aligment on a linear grid with equal spacing (stride).

This template would also work great for elements having integer types.
Many thanks in advance,

Nordlöw

Aug 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Nordlöw wrote:
Does anyone know of a C++ (template) (vector) container that packs its
elements based on their relative minimum and maximum value (offset and
span) and (minimum) stride.

Example:
The pointers [ 0x00, 0x04, 0x12, 0x20 ] when packed should be stored
internally in the template<Tcontainer as
T min: 0
T stride: 4
packed values: [ 0, 1, 3, 5 ] (in this case be stored in a
std::vector<uint8_t>)

I think such a container would be especially suitable for storing
"small" arrays of pointers. Especially on a 64-bit architecture where
a pointer takes 8 bytes, this would reduce memory usage by up to 8
times. This example, of course, holds only for the ideal case where
the array has exactly 256 number of elements and these elements are
all aligment on a linear grid with equal spacing (stride).

This template would also work great for elements having integer types.
Looks interesting. No, I've not seen, nor have I had any need to
implement, anything like that. To be entirely honest, sorting a list
(vector, set) of pointers based on pointer values is not a critical
task. Sorting a container of pointers based on the object values is
done frequently, but I am not sure how what you showed would help.

I am thinking of a container with indexing into another container, which
I've seen the need for, but sorting that one would still be done on some
kind of predicate not directly related to the pointer values, so, again,
only space savings have meaning.

Or, maybe I've misunderstood something...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 15 '07 #2

P: n/a
On 2007-08-15 15:44, Nordlöw wrote:
Hey there, C++ Coders.

Does anyone know of a C++ (template) (vector) container that packs its
elements based on their relative minimum and maximum value (offset and
span) and (minimum) stride.

Example:
The pointers [ 0x00, 0x04, 0x12, 0x20 ] when packed should be stored
internally in the template<Tcontainer as
T min: 0
T stride: 4
packed values: [ 0, 1, 3, 5 ] (in this case be stored in a
std::vector<uint8_t>)

I think such a container would be especially suitable for storing
"small" arrays of pointers. Especially on a 64-bit architecture where
a pointer takes 8 bytes, this would reduce memory usage by up to 8
times. This example, of course, holds only for the ideal case where
the array has exactly 256 number of elements and these elements are
all aligment on a linear grid with equal spacing (stride).
There's always the risk that such a scheme for pointers would result in
slower code due to the need to create a real pointer from the smaller
one you stored and then dereferencing it. Besides, if you have 64 bit
address space you probably also have physical memory enough that other
optimisations are more worthwhile.

--
Erik Wikström
Aug 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.