on b86b65f help sign in
46 lines 1.2 kB history raw
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE ExistentialQuantification #-}
4{-# LANGUAGE MagicHash #-}
5{-# LANGUAGE RecordWildCards #-}
6{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE TypeFamilies #-}
8{-# LANGUAGE UnboxedTuples #-}
9{-# LANGUAGE FlexibleContexts #-}
11#include "inline.hs"
13-- |
14-- Module : Streamly.Memory.Malloc
15-- Copyright : (c) 2019 Composewell Technologies
16--
17-- License : BSD3
18-- Maintainer : harendra.kumar@gmail.com
19-- Stability : experimental
20-- Portability : GHC
21--
22module Streamly.Memory.Malloc
23 (
24 mallocForeignPtrAlignedBytes
25 )
26where
28#define USE_GHC_MALLOC
30#ifndef USE_GHC_MALLOC
31import Foreign.ForeignPtr (newForeignPtr)
32import Foreign.Marshal.Alloc (mallocBytes, finalizerFree)
33#endif
35import qualified GHC.ForeignPtr as GHC
37{-# INLINE mallocForeignPtrAlignedBytes #-}
38mallocForeignPtrAlignedBytes :: Int -> Int -> IO (GHC.ForeignPtr a)
39#ifdef USE_GHC_MALLOC
40mallocForeignPtrAlignedBytes size alignment = do
41 GHC.mallocPlainForeignPtrAlignedBytes size alignment
42#else
43mallocForeignPtrAlignedBytes size _alignment = do
44 p <- mallocBytes size
45 newForeignPtr finalizerFree p
46#endif