[erlang-questions] binary alignment

Jachym Holecek <>
Mon Apr 14 14:25:38 CEST 2008


On Mon, 14 Apr 2008 13:56:29 +0200, Zvi <> wrote:
> I wander if it's possible either to create binaries already aligned, say  
> by
> 512 bytes. Or somehow get actual address of the binary and calculate  
> offset aligned by 512 bytes (512 bytes is just an example).

Just curious: why do you want to do something like that?

> In C++ code I doing something like this:
>
> const int ALIGNMENT_SIZE = 512;
> const int BUFFER_SIZE = 16384;
> unsigned char *pBuffer = new unsigned char[ALIGNMENT_SIZE + BUFFER_SIZE];
> unsigned char *pAlignedBuffer = (unsigned char*)( (unsigned
> int)(pBuffer+ALIGNMENT_SIZE) & ~(ALIGNMENT_SIZE-1) );

This will lose when sizeof(void *) > sizeof(int).

         -- Jachym




More information about the erlang-questions mailing list