473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Linearly Value Compressed Vector (Container)

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
2 1553
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: BCC | last post by:
Hi, A colleague has some code like this: class CMyObject { // Bunch of Member functions } class CMyObjectList: public std::vector<CMyObject> {
29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
41
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
6
by: marcwentink | last post by:
Dear Sirs, Dear Newsgroup, Imagine I have some function that only gives me an iterator to a vector, but not the vector itself. Unfortunately this vector can be empty and the iterator can point...
12
by: ypjofficial | last post by:
Hello All, I need to return a vector from a function.The vector is of int and it can contain as many as 1000 elements.Earlier I was doing //function definition vector<intretIntVector() {...
8
by: imutate | last post by:
I have a std::vector with each element being a class, I push_back elements and then store values in the class object, later I look at these objects and the values are null. In essence: class...
2
by: Ken Camann | last post by:
Hey everyone. First of all let me say that I know that the C++ standard never makes any guarantees about compiler implementation and thus about the performance of any language feature. That...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.