share a structure array containing multidimensional char array C#/



I want to share a structure array containing multi dimensional char array
between C# and C++, by using memory mapped file.

I already have C++ code for handling memory mapped file.
I am passing pointer to the structure array as shown below for C++;
I am able to work with pointer ( for C++ ).
C++ code works fine.

I am working on converting code for memory mapped file in C#.
My problems:
1. How should I define structure array in C# ( for the below structure array
).
2. How should I define pointer to structure array in C# ( for the below
structure array ).

Any help related to this would be highly appreciated.

C++ implementation:

struct msg_file_s
{
unsigned char mb_buffer[1000][1000];
.....
.....
};

struct msg_file_s msg_file[16];
struct msg_file_s *msg_file_ptr;


HANDLE api_map_memory(struct msg_file_s **msg_file_ptr)
{
HANDLE hKernel = CreateFileMapping ( (HANDLE) 0xFFFFFFFF,
NULL,

PAGE_READWRITE,
0,

sizeof( struct msg_file_s ),

_T("TEST"));

*msg_file_ptr = (struct msg_file_s *) MapViewOfFile( hKernel,

FILE_MAP_READ | FILE_MAP_WRITE,
0,
0,
0 );
return(hKernel);
}


map_memory_file(int index)
{
msg_file_ptr = &msg_file[index];
hKernel = api_map_memory(&msg_file_ptr);
}

/****************************************************************************/

C# implementation:

[StructLayout(LayoutKind.Sequential)]
unsafe struct msg_file_s
{
[MarshalAs(UnmanagedType.LPArray, ArraySubType= UnmanagedType.U1,
SizeConst = 100, SizeParamIndex=2)]
byte[,] mb_buffer;
}


--
Aykut ERGİN
Nortel Netaş
Software Design Engineer

.



Relevant Pages

  • Re: Send/Receive using MPI_Type_struct
    ... I'm trying to send and receive a structure array "TABLE". ... a pointer to pointer to pointer to char? ...
    (comp.lang.c)
  • Re: modify structure array pointer in the function
    ... > the follows is my program, I wanna change my structure array ... %x expects an unsigned int. ... You are passing a pointer. ...
    (comp.lang.c)
  • Re: Preallocating struct arrays
    ... My guess is allocating the structure array alone would not not improve much ... getframe will allocate memory to hold what it creates. ... You might as well just copy that pointer to the structure array as no ...
    (comp.soft-sys.matlab)

Loading