-
I embarrassingly ran into the 1<<24 byte size limit on a class and triggered the static_assert. I couldn't find a direct reference to this limit in the docs, did I miss it? Is nanobind designed to support objects that must be entirely allocated on the heap? I was actually surprised to see the limit, since I thought everything would be done on the heap anyway. How do I bind this sort of struct? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
I mean the obvious thing to do would be to struct Wrapper {
unique_ptr<UnreasonablyBigStruct> ptr;
}; Just wondering if there's a different way to do it. |
Beta Was this translation helpful? Give feedback.
-
I tried simply patching out the It would be very helpful to get a comment on this from the author/maintainer, to know if there are are any landmines here. |
Beta Was this translation helpful? Give feedback.
-
I'm reading the code and I see the limitation on number of flags (24 bits). But to me, it looks like max size is a full 32 bits: nanobind/include/nanobind/nb_class.h Lines 94 to 98 in bbbd022 am I misunderstanding? Or is the size limited in a different struct? |
Beta Was this translation helpful? Give feedback.
-
Fixed in 2aacdcf |
Beta Was this translation helpful? Give feedback.
The static_assert is needed. The information that nanobind stores about the type is fairly compressed, and only 24 bits are available to encode the size. You will have undefined behavior if nanobind ever tries to allocate such a class on its own (instead of allocating one in C++ and then returning it to Python), as it will not acquire enough memory for it.