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

From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 11/08/04


Date: Mon, 8 Nov 2004 13:32:46 +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.

Willy.

"Olaf Baeyens" <olaf.baeyens@skyscan.be> wrote in message
news:418f4198$0$32258$ba620e4c@news.skynet.be...
>I am porting some of my buffer class code for C++ to C#.
> This C++ class allocates a block of memory using
> m_pBuffer=new BYTE[...];
>
> But since the class is also used for pointers for funtions that uses raw
> MMX
> and SSE power, the starting pointer MUST be starting at a 16 byte memory
> boundary.
> In C++ I allocate more memory than needed, and in a second phase I search
> for the address that starts on a 16 byte boundary. And I then use that new
> memory address pointer.
>
> Is there a way to make C# to always align a "byte[] Buffer=new byte[132];"
> dynamically to a 16 byte memory address?
> [StructLayout(LayoutKind.???)] ???
>
> I am not talking about the location of &Buffer but about the location of
> &(new byte[132]).
> It would be nice if I could decide to make parts of my code aligned on 16
> bytes and the rest on normal 8 bytes or 32 byte depending on the need and
> not force all uses of Buffer to be alignend on 16 bytes..
>
> --
> http://www.skyscan.be
>
>



Relevant Pages

  • dgemm subroutine in BLAS - I think Ive cracked the difference, please confirm
    ... see what I'm talking about), so in the current state of memory allocation, ... but I have a problem when it comes to applying the dimensions. ... > In the Fortran 66 days it was because dynamic allocation didn't exist, ... > you allocate arrays big enough for the largest problem you might run into. ...
    (comp.lang.fortran)
  • memory allocation overhead
    ... features of the application is its memory management. ... dynamic memory allocation at this time were slow (inner ... dynamic size arrays at run time. ... The scratch arrays can be easily implemented as automatic arrays. ...
    (comp.lang.fortran)
  • Re: Memory Space
    ... more memory to store data arrays. ... HD and 4G of RAM and am only using several hundered meg of RAM in an array. ... a pared-down piece of code that shows the allocation ...
    (microsoft.public.vb.general.discussion)
  • Re: Recursive subroutine for reading null-terminated string
    ... ignoring the memory involved in the recursive call. ... I thought that normal arrays are allocated a single ... contains large chunks of data rather than single characters, ... Is memory allocation in general a serious problem in terms of speed/ ...
    (comp.lang.fortran)
  • [RFC 2/3] mm: Reimplement bootmem
    ... logic tried allocation on the first node in the system and dropped the ... * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999 ... * @flags: reservation flags ... * @align: alignment of the region ...
    (Linux-Kernel)