Direct Memory Access Help
- From: "O.B." <funkjunk@xxxxxxxxxxxxx>
- Date: Tue, 31 Oct 2006 10:17:15 -0600
Given the two following structures:
[StructLayout(LayoutKind.Explicit, Size=16)]
public struct Articulation {
[FieldOffset(0)] public byte typeDesignator; // 1 byte
[FieldOffset(1)] public byte changeIndicator; // 1 byte
[FieldOffset(2)] public Unsigned16 attachmentID; // 2 bytes
[FieldOffset(4)] public Unsigned32 type; // 4 bytes
[FieldOffset(8)] public Bits64 value; // 8 bytes
}
[StructLayout(LayoutKind.Explicit, Size=1392)]
public struct EntityState {
public static byte TYPE_ENTITY_STATE = 1;
[FieldOffset(0)] public Header header; // 12 bytes
[FieldOffset(12)] public EntityIdentifier entityID; // 6 bytes
[FieldOffset(18)] public ForceIdentifier forceID; // 1 byte
[FieldOffset(19)] public byte numArticulations; // 1 byte
[FieldOffset(20)] public EntityType type; // 8 bytes
[FieldOffset(28)] public EntityType altType; // 8 bytes
[FieldOffset(36)] public Vector linearVelocity; // 12 bytes
[FieldOffset(48)] public WorldCoordinate location; // 24 bytes
[FieldOffset(72)] public EulerAngles orientation; // 12 bytes
[FieldOffset(84)] public Unsigned32 appearance; // 4 bytes
[FieldOffset(88)] public DeadReckoning deadReckoning; // 40 bytes
[FieldOffset(128)] public EntityMarking marking; // 12 bytes
[FieldOffset(140)] public Unsigned32 capabilities; // 4 bytes
// In C#, you cannot have "public fixed Articulation
// articulations[78]" because "fixed" does not support
// reference types. Use memory pointers?
[FieldOffset(144)] public Articulation articulations;
}
As you can see, I hit a small problem where C# does not support "fixed" with a custom type. So, I'd like to add an operation to the EntityState structure that allows a user to load an articulation given an index.
// A workaround for this.articulations[index]
public Articulation getArticulationAt(int index);
In C#, how does one go about directly accessing memory to perform this behavior? Thanks in advance.
.
- Follow-Ups:
- Re: Direct Memory Access Help
- From: Willy Denoyette [MVP]
- Re: Direct Memory Access Help
- From: chanmm
- Re: Direct Memory Access Help
- Prev by Date: Why VS2005.IDE adds app.config to C# Class Library projects?
- Next by Date: Re: Adding a Click event to a Web Browser control
- Previous by thread: Why VS2005.IDE adds app.config to C# Class Library projects?
- Next by thread: Re: Direct Memory Access Help
- Index(es):