Re: UNION in struct
From: Ken Allen (kendrhyd_at_sympatico.ca)
Date: 06/07/04
- Next message: Dave.G: "Re: C# And Terminal Services"
- Previous message: TT (Tom Tempelaere): "Datagrid - where to initialize?"
- In reply to: Lasse Vågsæther Karlsen: "Re: UNION in struct"
- Next in thread: Frank Hileman: "Re: UNION in struct"
- Reply: Frank Hileman: "Re: UNION in struct"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 7 Jun 2004 06:33:20 -0400
No, you are missing my point. This struct is not used for serialization or
communicaiton between different components. The issue is that this specific
algorithm, which was written in C originally, uses a data structure to hold
the context for the algorithm at different phases. Within this structure is
a union of two arrays that occupy the same amount of physical memory -- some
of the code refers to the contents of this union as an array of bytes and
manipulates individual bytes, and then other parts of the same code refers
to the same union content as an array of integers and manipulates the
individual integer values.
In fact, I do not even need the structure if I convert this into a C# class
object, since the context variables can be data members of the class. But I
still need to have the ability to refer to a collection of a sequences of
128 bits as either an array of 16 bytes or an array of 4 ints. The algorithm
is extrmely compute intensive, and so I cannot afford any process (such as
marshalling the data into and out of an IntPtr buffer) -- what I would truly
like is a way to allocate the memory and then cast it as either an array of
16 bytes or 4 int values.
-ken
"Lasse Vågsæther Karlsen" <lasse@vkarlsen.no> wrote in message
news:Xns95016287EC3A8lassevkarlsenno@207.46.248.16...
> "Ken Allen" <kendrhyd@sympatico.ca> wrote in
> news:u8ZaASmSEHA.3200@TK2MSFTNGP10.phx.gbl:
>
> > On this same note, how does one declare an array in a struct and have
> > it take space within the struct -- my impressions is that the
> > declaration in the struct will be a reference to the array, which is
> > allocated elsewhere.
> >
>
> The only place where this would be useful is when dumping data to stream,
> or using interop.
>
> For interop, you can specify attributes on the array member that makes the
> marshalling code able to place the array into the marshalled data as
though
> it "were taking up space" in the struct.
>
> Look at the MarshalAs attribute class for more details.
>
> For dumping the struct to disk, you can do this with marshalling too. Just
> define the struct as though you were going to marshal it for interop, then
> convert it to a byte array before dumping it to the stream.
>
> --
> Lasse Vågsæther Karlsen
> lasse@vkarlsen.no
> PGP KeyID: 0x0270466B
- Next message: Dave.G: "Re: C# And Terminal Services"
- Previous message: TT (Tom Tempelaere): "Datagrid - where to initialize?"
- In reply to: Lasse Vågsæther Karlsen: "Re: UNION in struct"
- Next in thread: Frank Hileman: "Re: UNION in struct"
- Reply: Frank Hileman: "Re: UNION in struct"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|