Skip to content

More control over memory allocations (specifically images) #293

@BoyBaykiller

Description

@BoyBaykiller

I load Intel Sponza Base using SharpGLTF and notice that even after a couple of minutes my application has a weirdly high RAM usage of 5GB:
Image

Almost all of that comes from dead byte[] allocated by SharpGLTF:
Image

Explicitly calling GC.Collect() is needed:
Image

I'd rather not have my app keep Gigabytes of unused memory arround for no reason. SharpGLTF could make memory managment more transparent. We could focus on images only for now since those alone make up 2GB on this model.

As an example, currently all external images are loaded (even if the app never references them) into this managed byte[]. But this is not specific to external images.

filePath = System.IO.Path.GetFullPath(filePath);
var data = System.IO.File.ReadAllBytes(filePath);


I'd like to:

  1. Load images into my own memory
  2. Control when I load it
  3. Control if I load it at all

I don't know how other libaries handle this, but this is what I found fastgltf doing which has become quite popular recently: https://github.com/spnda/fastgltf/blob/7889b48e1435da943dcbeab5af4fbf7f39f1df0b/examples/gl_viewer/gl_viewer.cpp#L516-L555
Much more control is given to the user. I don't even need to make a copy. I can tell stbi image to load the image directly from the memory or file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions