ddiakopoulos / tinyply

:earth_africa: C++11 ply 3d mesh format importer & exporter
598 stars 118 forks source link

Provide custom memory for vertices #45

Open HiImJulien opened 4 years ago

HiImJulien commented 4 years ago

Hey there!

Given a class mesh, which (pre-)allocates it's own memory for storing up to n vertices. I cannot modify this class. Can I instruct TinyPly to use the preallocate memory instead of it allocating its own memory and having to copy the vertices?

ddiakopoulos commented 3 years ago

Can you explain you use-case a little bit more? It's the first time someone has requested this feature so I'm curious to know more. It's challenging namely because it's unclear (as an application developer) how much memory you need to preallocate and then what happens if the library needs to allocate more. Lots of things to consider :)

HiImJulien commented 3 years ago

The use case is pretty simple: Avoid unnecessary allocations and copies for big sets of data.

The storage size for per-element properties can be calculated pretty easily, thus preallocation can occur after the header was parsed. For lists, I agree, that's a real pain in the back, requiring you to iterate through each row and reading the element count.

fwilliams commented 2 years ago

I'm also interested in this feature. I'm using tinply as a loader in a python library which returns NumPy arrays. I'm often using this loader for massive meshes which take up a lot of memory. I would like to have tinyply load directly into the buffer allocated for the NumPy array rather than make a copy.