Reputation: 6464
I'm implementing C++ code communicating with hardware which runs a number of hardware-assisted data structures (direct access tables, and search trees). So I need to maintain a local cache which would store data before pushing it down on the hardware.
I think to replicate H/W tree structure I could choose std::map, but what about direct table (basically it is implemented as a sequential array of results and allows direct-access lookups)?
Are there close enough analogues in STL to implement such structures or simple array would suffice?
Thanks.
Upvotes: 0
Views: 714
Reputation: 991
C++11 has an unordered-map, and unordered-set, which are analogous to a hash table. Maps are faster for iteration, while sets are faster for look up.
But first you should run a profiler to see if your data-structures are what slows your program down
Upvotes: 0
Reputation: 28872
If you are working with hardware structures, you are probably best off mimicking the structures as exactly as possible using C struct
s and C arrays.
This will give you the ability to map the hardware structure as exactly as possible and to move the data around with a simple memcpy
.
The STL will probably not be terribly useful since it does lots of stuff behind the scenes and you have no control of the memory layout. This will mean that each write to hardware will involve a complex serialization exercise that you will probably want to avoid.
Upvotes: 3
Reputation: 171107
I believe you're looking for std::vector
. Or, if the size is known at compile time, std::array
(since C++11).
Upvotes: 1