C#C
C#3y ago
streepje8

[SOLVED] Storing pointers in an array instead of the objects themselves?

Id like to store some objects in an array like this. I know that the array will contain a lot of empty spots so I would like to store pointers instead of reserving space for the entire object. Sadly this does not seem to be possible because the object is a managed object.
public class RuntimeObject : SerializeableObject { }

public class SerializeableObject
{
    public virtual string Serialize() => "";
    public virtual RuntimeObject Deserialize(string data) => null;
}

I don't think that storing the data in an array like this is the most optimal way, but seeing that I need the data in a 2D array like structure this is the most performant thing I could come up with.
I was also thinking about storing an array of dictionaries to get rid of the empty spots, only that would increase lookup time.
If anyone has a better alternative to this please let me know ^_^

(The reason why the array contains a lot of empty spots is because the lookup index matters, things in the x direction are of the same type, and things in the y direction are related to eachother)
image.png
Was this page helpful?