From ec4ccb2e9c629ba3ebc53f47bf57d1bf1683bd44 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sun, 28 Aug 2022 06:57:02 -0700 Subject: [PATCH] Added `GetAllocSize` to `FlexibleArrayAttribute` --- BeefLibs/corlib/src/Interop.bf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/Interop.bf b/BeefLibs/corlib/src/Interop.bf index 6867c1d7..dbfe793b 100644 --- a/BeefLibs/corlib/src/Interop.bf +++ b/BeefLibs/corlib/src/Interop.bf @@ -108,7 +108,10 @@ namespace System if ((field.FieldType == null) || (!field.FieldType.IsSizedArray) || (field.FieldType.Size != 0)) Runtime.FatalError("Type must end in a zero-sized array"); var elementType = (field.FieldType as SizedArrayType).UnderlyingType; - Compiler.EmitTypeBody(type, scope $"public {elementType}* {mName} mut => (({elementType}*)((uint8*)&this + Math.Align(typeof(Self).Size, typeof({elementType}).Align)));"); + Compiler.EmitTypeBody(type, scope $""" + public {elementType}* {mName} mut => (({elementType}*)((uint8*)&this + Math.Align(typeof(Self).Size, typeof({elementType}).Align))); + public static int GetAllocSize(int arrayCount) => Math.Align(typeof(Self).Size, typeof({elementType}).Align) + typeof({elementType}).Size*arrayCount; + """); } } }