Re: "new byte[132]" alignment on 16 bytes
From: Olaf Baeyens (olaf.baeyens_at_skyscan.be)
Date: 11/08/04
- Next message: John Sutor: "Re: Formatting numbers with events"
- Previous message: Juan: "pls help: how can i select a just inserted row in a datagrid (using a dataset as datasource)?"
- In reply to: Willy Denoyette [MVP]: "Re: "new byte[132]" alignment on 16 bytes"
- Next in thread: Willy Denoyette [MVP]: "Re: "new byte[132]" alignment on 16 bytes"
- Reply: Willy Denoyette [MVP]: "Re: "new byte[132]" alignment on 16 bytes"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 8 Nov 2004 13:59:16 +0100
> What exactly do you mean with "C# to always align a....". C# doesn't align
> anything. Byte arrays are allocated on the managed heap and this
allocation
> is done by the CLR, the application code cannot control the alignment nor
> the location.
> However, as your functions are unmanaged code and as such, you have to
copy
> the byte arrays to unmanaged memory anyway, no-one stops you from
> implementing some form of custom marshalling.
>
Well I want to create a byte[] Buffer=new byte[xxx] ;
And pass this Buffer to a unmanaged C++ function that executes Assembler SSE
instructions on this buffer without having to copy the memory block.
The SSE instructon set assumes that the starting physical memory block is
starting at a address location that is devidable by 16 or else it generates
an exception.
Copying a memory block is no option since these are huge memory blocks. The
intention of using SSE is just to speed up calculations, but if I need to
copy the memory block the SSE would not be a solution in my case. Another
technique should then be used.
In code examples I see [StructLayout(LayoutKind.???)] beeing used as way
for alignment of a structure. But this alignes the buffer pointer, not the
actual memory address of the data.
So if it works for structures, then there might also be a way to align for
byte arrays.
An alternative is that I still use unmanaged C++ to allocate aligned memory
blocks, and then pass this on to C#, but I would really prefer that C# can
do this instead.
-- http://www.skyscan.be
- Next message: John Sutor: "Re: Formatting numbers with events"
- Previous message: Juan: "pls help: how can i select a just inserted row in a datagrid (using a dataset as datasource)?"
- In reply to: Willy Denoyette [MVP]: "Re: "new byte[132]" alignment on 16 bytes"
- Next in thread: Willy Denoyette [MVP]: "Re: "new byte[132]" alignment on 16 bytes"
- Reply: Willy Denoyette [MVP]: "Re: "new byte[132]" alignment on 16 bytes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|