Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the size of memory allocated for tinygltf::Mesh and tinygltf::Image #389

Open
lsong0905 opened this issue Nov 1, 2022 · 3 comments

Comments

@lsong0905
Copy link

Hello,

I am working on a project that requires to cache tinygltf::Mesh and tinygltf::Image objects. Since we have a limited amount of memory allocated for cache, I am wondering if there is a quick way to get the size of tinygltf::Mesh or tinygltf::Image object, including the dynamically allocated memory in the object. Thank you in advance!

@syoyo
Copy link
Owner

syoyo commented Nov 1, 2022

There is no such functionalities yet. Contribution is much appreciated!

It'd be also better to have a feature to cap memory use for Graphics primitives and assets when loading, as I'm doing in TinyUSDZ: https://github.com/syoyo/tinyusdz/blob/781d4c2a24020518cec1d171a45a5defcb386d49/src/tinyusdz.hh#L92

@lsong0905
Copy link
Author

@syoyo Thanks for the reference about capping memory use for assets. That's a good suggestion.
I will see if I can add an allocator that keeps track of the size of buffer. Do you have any code pointer that where could be a good place to start with?

@syoyo
Copy link
Owner

syoyo commented Nov 1, 2022

@lsong0905 You can simply put a code for recording memory growth to proper place(e.g. before std::vector::resize) like this: https://github.com/syoyo/tinyusdz/blob/781d4c2a24020518cec1d171a45a5defcb386d49/src/crate-reader.cc#L381

https://github.com/syoyo/tinyusdz/blob/781d4c2a24020518cec1d171a45a5defcb386d49/src/crate-reader.cc#L62

Its simple(boring task though), but would work well.

If you want to get an information of image data(width, height, bits, etc) from compressed data through default image loader(stbi), You can use stbi_info_** to get such an information:
https://github.com/syoyo/tinyusdz/blob/781d4c2a24020518cec1d171a45a5defcb386d49/src/image-loader.cc#L132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants