© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
41 replies
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 RuntimeObject : SerializeableObject { }

public class SerializeableObject
{
    public virtual string Serialize() => "";
    public virtual RuntimeObject Deserialize(string data) => null;
}
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Pointers in C#
C#CC# / help
3y ago
I need help declaring an array of objects where the attributes of the properties are user inputted.
C#CC# / help
4mo ago