0

I'm working on an Entity-Component System, and now that I got everything up and running I decided to delve a bit into optimizations. Currently, I have a Gameobject class that stores an unordered_map with component IDs and respective component pointers. To speed things up, I want to try to allocate components on the heap in contiguous memory without copying them into a vector. With this I would be able to iterate over them simply by getting the first component then moving up from that address by the size of the component, essentially eliminating the constant searching the computer would otherwise have to go through to find the different memory addresses when iterating over their pointers.

Is there a way to do such a thing?

trincot
  • 317,000
  • 35
  • 244
  • 286
Its Me
  • 174
  • 1
  • 8
  • I tend to agree with the answer [here](https://stackoverflow.com/a/14385809/13020139). If looping through the map is the dominant operation of this map, `unordered_map` probably isn't what you want. Seems like either you go with an array-like data structure that is automatically contiguous, or you write your own data struct for this. – wxz Apr 03 '21 at 00:50
  • The unordered_map is used both for iteration and for finding components by their IDs and retrieving their pointers, but yeah, writing my own structure for containing the data is starting to seem like my best option – Its Me Apr 03 '21 at 00:57

0 Answers0