File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -853,13 +853,27 @@ impl Bindgen for FunctionBindgen<'_, '_> {
853853 //TODO: wasm64
854854 let align = self . interface_gen . csharp_gen . sizes . align ( element) . align_wasm32 ( ) ;
855855
856+ let ( array_size, element_type) = crate :: world_generator:: dotnet_aligned_array (
857+ size,
858+ align,
859+ ) ;
860+ let ret_area = self . locals . tmp ( "retArea" ) ;
861+
856862 self . needs_cleanup = true ;
857863 uwrite ! (
858864 self . src,
859865 "
860- var {buffer_size} = {size} * (nuint){list}.Count;
861- var {address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
862- cleanups.Add(()=> NativeMemory.AlignedFree({address}));
866+ void* {address};
867+ if (({size} * {list}.Count) < 1024) {{
868+ var {ret_area} = stackalloc {element_type}[({array_size}*{list}.Count)+1];
869+ {address} = (void*)(((int){ret_area}) + ({align} - 1) & -{align});
870+ }}
871+ else
872+ {{
873+ var {buffer_size} = {size} * (nuint){list}.Count;
874+ {address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
875+ cleanups.Add(()=> NativeMemory.AlignedFree({address}));
876+ }}
863877
864878 for (int {index} = 0; {index} < {list}.Count; ++{index}) {{
865879 {ty} {block_element} = {list}[{index}];
You can’t perform that action at this time.
0 commit comments