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

Stack allocate cgltf_data structure? #224

Open
Torphedo opened this issue Jul 1, 2023 · 1 comment
Open

Stack allocate cgltf_data structure? #224

Torphedo opened this issue Jul 1, 2023 · 1 comment

Comments

@Torphedo
Copy link

Torphedo commented Jul 1, 2023

Is there some technical reason behind using a dynamic allocation for the cgltf_data output structure? Since it's a static size, I think it would be more convenient and practical to do something like this:

#define CGLTF_IMPLEMENTATION
#include "cgltf.h"

void* buf; /* Pointer to glb or gltf file data */
size_t size; /* Size of the file data */

cgltf_options options = {0};
cgltf_data data = {0};
cgltf_result result = cgltf_parse(&options, buf, size, &data);
if (result == cgltf_result_success) {
    /* [Do stuff with data] */
}
@zeux
Copy link
Contributor

zeux commented Jul 22, 2023

You’d still need cgltf_free; it’s easier to forget in code like above. With that it doesn’t seem like ergonomics is any better, and cgltf allocates enough that one extra allocation won’t matter for performance.

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

No branches or pull requests

2 participants