foundation icon indicating copy to clipboard operation
foundation copied to clipboard

Add alloca and malloc

Open sighingnow opened this issue 8 years ago • 4 comments

How to allocate memory and pass the ptr to foreign C code using foundation ?

sighingnow avatar Sep 07 '17 13:09 sighingnow

you can use base's alloca and malloc functions. The Ptr type is the same.

You should be able to use the two following lines together without issues:

import Foreign.Marshal.Alloc (alloca, malloc)
import Foundation.Class.Storable

NicolasDP avatar Sep 07 '17 16:09 NicolasDP

And for foreign pointer, you can do more or less the same.

NicolasDP avatar Sep 07 '17 16:09 NicolasDP

Importing alloca and malloc from base directly does work.

But we still can't use the alloc and malloc to do allocation if we only have made our custom type as the instance of foundation's Storable without the instance of base's Storable. Is there any plan for providing allocate functions for foundation's Storable ?

sighingnow avatar Sep 08 '17 01:09 sighingnow

ha I see. Ok, good point. Now there is a plan !

NicolasDP avatar Sep 08 '17 09:09 NicolasDP