title: Creating a generalized resource map without using strings?
body: <p>Let's assume I want to create an object that will hold some arbitrary data.</p>
  
  <pre><code>// Pseudocode
  class MyContainer {
      map&lt;key, pair&lt;void*, size&gt;&gt;;
  }
  </code></pre>
  
  <p>The key in this case also identifies the kind of data stored in the void* (e.g an image, a struct of some kind, maybe even a function).</p>
  
  <p>The most general way to del with this is have the key be a string. Then you can put whatever on earth you want and then you can just read it. As a silly example, the key can just be:</p>
  
  <pre><code>"I am storing a png image and the source file was at location/assets/image.png and today is sunday".
  </code></pre>
  
  <p>i.e you can encode whatever you want. This is however slow. A much faster alternative is using enumerators and your keys are then <code>IMAGE</code>, <code>HASHMAP</code>, <code>FUNCTION</code>, <code>THE_ANSWER_TO_LIFE</code>...</p>
  
  <p>However that requires you know every single case you need to handle beforehand and create an enumerator for it manually (which is tedious and not very extensible).</p>
  
  <p>Is there a compromise that can be made? i.e something that uses only one key but is faster than strings and more extensible than enums?</p>
  
  <p>Edit:
  The exact use case I am trying to use this for is as a generalized storage for rendering data. This includes images, vertex buffers, volumetric data, lighting information... Or any other conceivable thing you may need.</p>
  
  <p>The only way I know to create "absolute polymorphism" (i.e represent literally any form of conceivable data) is to use void pointers and rely on algorithms to understand the data.</p>
  
  <p>Example:</p>
  
  <p>Say our key is a JSON string where the key of each element is the name of a field in a compact struct and the value is the offset in bytes.</p>
  
  <p>E.g </p>
  
  <pre><code>  {
         m_field1: 0,
         m_field2: 32,
         m_field3: 128,
     }
  </code></pre>
  
  <p>Then to access any of the elements in the void* all you need to do is do symbol manipulation to get the number and then <code>ptr + offset</code>.</p>
  
  <p>You can do the same with a set of unique identifiers (enums) and associated functions that get you the fields based on the identifier (hard coded approach).</p>
  
  <p>Hopefully this makes the question less obscure.</p>