Managed buffer alignment 
Author Message
 Managed buffer alignment

Is there any way to guarantee the memory alignment of a managed array of
bytes?

I'd like to take advantage of garbage-collection in the CLR, but my SSE2
routines require 16-byte alignment.

I was hoping for something like this, but couldn't find anything:
    Byte buffer __gc [] = new Byte __gc [1024];
    GC::Align(buffer, 16);

I know I could over-allocate my buffers, keep them pinned for the duration
of execution and ignore the first few unaligned bytes.  If that's my only
option, I may as well continue to use unmanaged buffers.

-Sean



Wed, 29 Jun 2005 10:01:45 GMT  
 Managed buffer alignment

Quote:
> Is there any way to guarantee the memory alignment of a managed array
> of bytes?

The clr does not currently provide a way to do this.

--
Jeff Peil



Wed, 29 Jun 2005 13:26:38 GMT  
 Managed buffer alignment

Quote:
> Is there any way to guarantee the memory alignment of a managed array of
> bytes?

> I'd like to take advantage of garbage-collection in the CLR, but my SSE2
> routines require 16-byte alignment.

Just curious about your question. What makes the difference between aligned
memory and unaligned? (I know what *is* the difference) so what does it
cause if a memory alloc is 'unaligned'...


Wed, 29 Jun 2005 16:46:55 GMT  
 Managed buffer alignment
It depends on what you try to do with it. In Sean case it simply would not
work since SSE2 instructions require 16 byte alignment to work at all. In
some other cases using non aligned data is just slower (from somewhat to
orders of magnitude depending on the CPU)

Ronald



Quote:


> > Is there any way to guarantee the memory alignment of a managed array of
> > bytes?

> > I'd like to take advantage of garbage-collection in the CLR, but my SSE2
> > routines require 16-byte alignment.

> Just curious about your question. What makes the difference between
aligned
> memory and unaligned? (I know what *is* the difference) so what does it
> cause if a memory alloc is 'unaligned'...



Thu, 30 Jun 2005 07:28:02 GMT  
 Managed buffer alignment

Quote:
> > Is there any way to guarantee the memory alignment of a managed array
> > of bytes?

> The clr does not currently provide a way to do this.

Ok.  Unmanaged buffers it is.

Have others expressed interest in such a feature?

-Sean



Thu, 30 Jun 2005 09:52:22 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. alignment and application-managed memory

2. Byte buffer cast in Managed C++

3. Using native buffers in managed code?

4. Using native buffers in managed code?

5. data alignment (was Re: RISC data alignment, in comp.arch)

6. How can I copy an unmannaged buffer to a managed buffer?

7. managed code vs. non-managed code

8. using Managed dlls from Managed C++

9. Managed array of managed arrays of char

10. moving arrays from un-managed to managed code.

11. Passing managed objects through non-managed exported functions

12. buffer and &buffer

 

 
Powered by phpBB® Forum Software