Re: "new byte[132]" alignment on 16 bytes
From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 11/08/04
- Next message: Guest: "Re: pls help: how can i select a just inserted row in a datagrid (using a dataset as datasource)?"
- Previous message: Olaf Baeyens: "Re: "new byte[132]" alignment on 16 bytes"
- In reply to: Olaf Baeyens: "Re: "new byte[132]" alignment on 16 bytes"
- Next in thread: Daniel Jin: "Re: "new byte[132]" alignment on 16 bytes"
- Reply: Daniel Jin: "Re: "new byte[132]" alignment on 16 bytes"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 8 Nov 2004 15:26:11 +0100
Olaf,
See inline ***
Willy.
"Olaf Baeyens" <olaf.baeyens@skyscan.be> wrote in message
news:418f6da4$0$15719$ba620e4c@news.skynet.be...
>> 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.
>
*** If copying is not an option, and pinning is not an option (it shouldn't
be), I would say Managed code is not an option too.
You can't solve all problems using managed code, that's why you (think you)
needed assembly code to solve the SSE issue and that's why you will need
another memory allocator to solve this too.
> 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.
>
*** StructLayout doesn't change anithing on the managed heap, it's just a
directive for the marshaler to change the layout when marshaling to/from
unmanaged memory.
> 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.
*** This is the only option. And again C# has nothing to do with this, C#
has no memory allocator, it's a task for the CLR's heap manager which is the
common runtime for all managed languages.
>
> --
> http://www.skyscan.be
>
>
- Next message: Guest: "Re: pls help: how can i select a just inserted row in a datagrid (using a dataset as datasource)?"
- Previous message: Olaf Baeyens: "Re: "new byte[132]" alignment on 16 bytes"
- In reply to: Olaf Baeyens: "Re: "new byte[132]" alignment on 16 bytes"
- Next in thread: Daniel Jin: "Re: "new byte[132]" alignment on 16 bytes"
- Reply: Daniel Jin: "Re: "new byte[132]" alignment on 16 bytes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|