Re: "new byte[132]" alignment on 16 bytes

From: Olaf Baeyens (olaf.baeyens_at_skyscan.be)
Date: 11/08/04


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


Relevant Pages

  • Re: malloc vs. realloc
    ... on your particular compiler and operating system, ... Perhaps a better memory allocation ... If you really need to shrink the memory block, ...
    (comp.lang.c)
  • Re: Avoiding copying an array in JNI
    ... The memory block keeps track of where it is in the processing - and so it essentially runs in to background until done. ... The calling program keeps calling the dll until the dll says it is 100% done. ... But this copy - with accompanying allocation of a new block of memory - makes the processing impossible. ... preserving the computation's state when the GUI needs the ...
    (comp.lang.java.help)
  • Re: amount of memory allocated to a pointer
    ... On implementations where this is available, it works with malloc'ed blocks ONLY. ... It tends to give sizes larger than the allocated size; Giving the effective size of allocation, ... With typical C functions accepting a pointer memory block as parameter as well as some size information, you can pass memory you've allocated from anywhere, you can write your own memory pool or sub-heap of malloc's heap, you can manually cut your memory blocks in pieces. ... Programmers are very used to have the freedom of memory use. ...
    (comp.lang.c)
  • Re: When to use automatic variables and when to use malloc
    ... I suspect that forgetting to deallocate the memory block ... And unlike malloc(), variable length arrays don't let you recover when ...
    (comp.lang.c)
  • Re: how many function copy will be created for normal member function and static member function ??
    ... Jigar Mehta wrote: ... what if we make 10 objects of that class, will 10 different allocation of memory block be made for each object for that member function ?? ...
    (microsoft.public.vc.language)