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 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
>
>



Relevant Pages

  • [rfc][patch 2/3] mm: bootmem2 - memory block oriented boot time allocator
    ... A boot time allocator that uses a bitmap for all pages in the system, ... +static inline int bootmem_node_block ... * A memory block oriented boot-time allocator. ...
    (Linux-Kernel)
  • Re: How can I have a DLL write data to my applications form? (eg. DLLs and procedural type question
    ... Yes, you could use the heap allocator functions, but no the COM memory ... since the standard memory manager as well as the sharemem manager are ...
    (comp.lang.pascal.delphi.misc)
  • Re: Delphi memory manager.
    ... The Heap manager does it's own sequencing. ... dwBytes: longword): Pointer; stdcall; ... // Deallocate memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: unmanaged vs managed.
    ... Above article is based on what is found in SSCLI and does not reveal that much about the CLR memory manager's internals, nor does it include anything really useful about the GC and the JIT implementation in the commercial CLR product. ... Note that in following I denote by *Heap*, the "Heap Managers" heap, while with *GC-Heap* I denote the CLR managed heap. ... It's quite obvious that the CLR has it's own memory manager, after all the *GC-Heap* is THE CLR's private heap, no other component in the system uses/manages the GC-Heap but the CLR. ... The CLR Object Manager allocates from the GC-Heap, while the GC keeps the GC-Heap "clean" in close cooperation with the CLR Memory Allocator or an external Memory allocator like the one used when you run the CLR in the SQL Host. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Wait free queue
    ... For some strange reason, I am ... blocks from any other allocator by any thread, ... memory block management. ...
    (comp.programming.threads)