#include "inline.hs"
module Streamly.Internal.Foreign.Malloc
(
mallocForeignPtrAlignedBytes
, mallocForeignPtrAlignedUnmanagedBytes
)
where
import Foreign.ForeignPtr (ForeignPtr, newForeignPtr_)
import Foreign.Marshal.Alloc (mallocBytes)
#ifdef USE_C_MALLOC
import Foreign.ForeignPtr (newForeignPtr)
import Foreign.Marshal.Alloc (finalizerFree)
#endif
import qualified GHC.ForeignPtr as GHC
{-# INLINE mallocForeignPtrAlignedBytes #-}
mallocForeignPtrAlignedBytes :: Int -> Int -> IO (GHC.ForeignPtr a)
#ifdef USE_C_MALLOC
mallocForeignPtrAlignedBytes size _alignment = do
p <- mallocBytes size
newForeignPtr finalizerFree p
#else
mallocForeignPtrAlignedBytes :: forall a. Int -> Int -> IO (ForeignPtr a)
mallocForeignPtrAlignedBytes =
forall a. Int -> Int -> IO (ForeignPtr a)
GHC.mallocPlainForeignPtrAlignedBytes
#endif
mallocForeignPtrAlignedUnmanagedBytes :: Int -> Int -> IO (ForeignPtr a)
mallocForeignPtrAlignedUnmanagedBytes :: forall a. Int -> Int -> IO (ForeignPtr a)
mallocForeignPtrAlignedUnmanagedBytes Int
size Int
_alignment = do
Ptr a
p <- forall a. Int -> IO (Ptr a)
mallocBytes Int
size
forall a. Ptr a -> IO (ForeignPtr a)
newForeignPtr_ Ptr a
p