Re: UNION in struct

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Ken Allen (kendrhyd_at_sympatico.ca)
Date: 06/07/04


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



Relevant Pages

  • Re: Marshalling Question: Array of Complex Structs?
    ... I get back an array of length 1 (I've only got one radio so this ... but that one struct contains only the initialization values I ... You can just tell the marshalling layer to embed the string into the ... public UInt32 Features; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: Passing an array of structuresfrom a pointer?
    ... I've tried an attempt to do that, and I tried to "clean" the header and main ..c file. ... int LIST_NUMBER; ... typedef struct ddListBox{ ... DDLB_COLL1array! ...
    (microsoft.public.vc.language)
  • Re: Marshalling Question: Array of Complex Structs?
    ... C style arrays don't have any information about the length of the array, ... but that one struct contains only the initialization values I ... You can just tell the marshalling layer to embed the string into the ... public UInt32 Features; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Marshalling Question: Array of Complex Structs?
    ... You could have used Int64 in the structure declaration. ... I've used no managed types within the struct. ... C style arrays don't have any information about the length of the array, ... >> You can just tell the marshalling layer to embed the string into>> the ...
    (microsoft.public.dotnet.languages.csharp)