user1454902
user1454902

Reputation: 738

Fixed struct array inside another struct?

I need an array of structs (which ARE all unmanaged structs with a fixed size) but apparently visual studio does not like my code.

Basically I NEED something like

fixed page_table tables[1024]; in my struct.

This is the code that makes visual studio throw a fit, is there anyway I can achieve this (and I need it all pre-initialized)

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public unsafe struct page_directory
{
    [FieldOffset(0)]
    public fixed page_table tables[1024];

    [FieldOffset(0x8000)]
    public fixed uint tablesPhysical[1024];

    [FieldOffset(0x9000)]
    public uint physicalAddr;
}

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public unsafe struct page_table
{
    [FieldOffset(0)]
    public fixed page pages[1024];
}

Upvotes: 0

Views: 179

Answers (1)

Guffa
Guffa

Reputation: 700322

The error message is pretty clear. You can't use any other types than the listed with a fixed buffer.

The error message even gives you the possible solutions, either use one of the allowed types, or don't use a fixed buffer.

If you really need the code that you are trying to use, then you have reached the point where it's simply not possible to do whatever you are trying to do.

Upvotes: 1

Related Questions