[LLVMdev] Memory Alignment, Heap allocation.

Chris Lattner sabre at nondot.org
Mon Jun 14 23:48:02 PDT 2004


On Mon, 14 Jun 2004, John Criswell wrote:
> > I'm currently implementing a small scheme toy-compiler, and want to use
> > the lowest 2 bits for type tags. It's Currently 380 lines of
> > scheme-code[1], quite similar to the compiler in SICP[2], which I hope to
> > get self-applicable later on.
>
> I think the only reliable way you could do this would be to implement
> your own memory allocator function that returned memory from the heap.
> Your code could ensure that every pointer it returned was on a 4 byte
> boundary.

I just wanted to add that the llvm "malloc" instruction turns into a
direct call to the libc malloc implementation.  All libc implementations
that I know of guarantee at least a 4-byte alignment, and many provide 8
byte.  If you malloc your data, you should be fine.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list