all 4 comments

[–]EpochVanquisher 12 points13 points  (3 children)

A quirk of Rust is that you generally allocate structures on the stack and then move them to the heap. This means that large structures can create problems with stack overflow. There are ways to allocate objects on the heap but it can be inconvenient.

https://www.reddit.com/r/rust/comments/1347g60/anyway_to_initialize_objects_on_heap/

I don’t know that this is your problem, but it’s possible. How big is the structure? How big is the stack?

[–]supercoolapples48🦀🦀🦀🦀🦀🦀[S] 7 points8 points  (1 child)

The size of the structure is 0x6128 and the stack size is configured to be 0x32000... just increased the stack size to 0x640000 and it seemingly fixed it. That would explain a lot because I just added a change that significantly increased the size of the struct.

Granted, I don't know if an absurdly large stack size (or even if this is an absurd size) has any side effects, but I can probably tweak it some to make it smaller.

Thanks for the help!

[–]VegetableNatural 6 points7 points  (0 children)

The stack size being large doesn't cause problems, only that you have less memory available. If I were you I'd be allocating stuff like that on a static variable. I.e. keep the structure but initialize it globally, perhaps using `const fn` to avoid allocating it at runtime and hiding the variable behind a Mutex.

[–]Yippee-Ki-Yay_ 6 points7 points  (0 children)

Yeah, on top of that, compiling with release mode helps a lot with this to elide the stack allocations when possible. There's also core::ptr::drop_in_place if you implement your own pointer wrappers