Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Add alloca and malloc #400

Open
sighingnow opened this issue Sep 7, 2017 · 4 comments
Open

Add alloca and malloc #400

sighingnow opened this issue Sep 7, 2017 · 4 comments
Labels
D - easy Difficulty easy for beginners

Comments

@sighingnow
Copy link
Contributor

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

@NicolasDP
Copy link
Member

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
Copy link
Member

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

@sighingnow
Copy link
Contributor Author

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 ?

@NicolasDP
Copy link
Member

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

@NicolasDP NicolasDP added D - easy Difficulty easy for beginners enhancement labels Sep 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
D - easy Difficulty easy for beginners
Projects
None yet
Development

No branches or pull requests

3 participants