Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better space-efficiency with Unsafe.* #61

Open
SupinePandora43 opened this issue Oct 9, 2023 · 1 comment
Open

Better space-efficiency with Unsafe.* #61

SupinePandora43 opened this issue Oct 9, 2023 · 1 comment

Comments

@SupinePandora43
Copy link

SupinePandora43 commented Oct 9, 2023

[Variant]
readonly partial struct SceneObjectParameter
{
	static partial void VariantOf(
		double @double,
		float @float,
		int @int
	);
}

internally uses

private readonly struct Union
{
	double @double;
	float @float;
	int @int;
}

but a more space-efficient structure can be used instead:

[StructLayout(LayoutKind.Explicit, Size = 8)]
private readonly struct Union
{
	double @double;
}

with the use of Unsafe.BitCast<TFrom,TTo>/Unsafe.As<TFrom,TTo> for access.

Reference types can use a single object.

@mknejp
Copy link
Owner

mknejp commented Oct 9, 2023

Yes, you are right. Layout optimization is currently disabled because I ran into problems with TypeLoadException. It's still on my radar but I have to find the time to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants