Re: Struct with fixed-length array member - is it possible?
- From: "Daniel O'Connell [C# MVP]" <onyxkirx@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Apr 2005 22:01:29 -0500
"Rafal Gwizdala" <gwrafal@xxxxxxxxxxxxxx> wrote in message
news:uD0e2CGRFHA.1172@xxxxxxxxxxxxxxxxxxxxxxx
> Hello,
>
>
> Can you provide some hints on how would you solve a problem like this? I'm
> out of ideas...
> Here's the problem: Let's imagine a C structure containing a fixed-size
> array
>
> struct XYZ
> {
> int V1;
> int V2;
> double V3[50];
> };
>
> This structure, when allocated, occupies a contiguous block of memory (408
> bytes in my compiler).
> Now I would like to have the same structure in C#, such that it would have
> THE SAME MEMORY LAYOUT as the C structure. The memory size does not need
> to be identical as in C, but the structure should occupy a single memory
> block and all data, including the array, should be placed in this block.
>
> There is no possibility in C# to declare a fixed-size array and to 'embed'
> it completely in a struct. When I make a declaration like this:
>
> public struct XYZ
> {
> int V1;
> int V2;
> double[] V3;
> }
>
2.0 offers this, finally, using the fixed keyword
public stuct XYZ
{
fixed double V3[50];
}
This requires unsafe code, however.
.
- References:
- Struct with fixed-length array member - is it possible?
- From: Rafal Gwizdala
- Struct with fixed-length array member - is it possible?
- Prev by Date: Re: Array of value-types
- Next by Date: Re: Regex parsing e-mail question.
- Previous by thread: Struct with fixed-length array member - is it possible?
- Next by thread: Array of value-types
- Index(es):
Relevant Pages
|