on master help sign in
Provide a flag to use the C malloc instead of the default GHC malloc
commit9ccf93168b67ab8bccf58fdd18fc2c56f8573d1c authoradithyaov <adi.obilisetty@gmail.com> dateFri 28 Aug 2020, 00:41 (6 years ago) parent02f7ce0
2 files changed+15−6
src/Streamly/Memory/Malloc.hs+7−6 streamly.cabal+8
src/Streamly/Memory/Malloc.hs+7−6
@@ -16,11 +16,12 @@ module Streamly.Memory.Malloc
1616 )
1717where
1818
19−#define USE_GHC_MALLOC
19+
20+-- We use GHC malloc by default
2021
2122import Foreign.ForeignPtr (ForeignPtr, newForeignPtr_)
2223import Foreign.Marshal.Alloc (mallocBytes)
23−#ifndef USE_GHC_MALLOC
24+#ifdef USE_C_MALLOC
2425import Foreign.ForeignPtr (newForeignPtr)
2526import Foreign.Marshal.Alloc (finalizerFree)
2627#endif
@@ -29,13 +30,13 @@ import qualified GHC.ForeignPtr as GHC
2930
3031{-# INLINE mallocForeignPtrAlignedBytes #-}
3132mallocForeignPtrAlignedBytes :: Int -> Int -> IO (GHC.ForeignPtr a)
32−#ifdef USE_GHC_MALLOC
33−mallocForeignPtrAlignedBytes =
34− GHC.mallocPlainForeignPtrAlignedBytes
35−#else
33+#ifdef USE_C_MALLOC
3634mallocForeignPtrAlignedBytes size _alignment = do
3735 p <- mallocBytes size
3836 newForeignPtr finalizerFree p
37+#else
38+mallocForeignPtrAlignedBytes =
39+ GHC.mallocPlainForeignPtrAlignedBytes
3940#endif
4041
4142-- memalign alignment size
streamly.cabal+8
@@ -204,6 +204,11 @@ flag examples-sdl
204204 manual: True
205205 default: False
206206
207+flag use-c-malloc
208+ description: Use C malloc instead of GHC malloc
209+ manual: True
210+ default: False
211+
207212-------------------------------------------------------------------------------
208213-- Common stanzas
209214-------------------------------------------------------------------------------
@@ -222,6 +227,9 @@ common compile-options
222227 if flag(inspection)
223228 cpp-options: -DINSPECTION
224229
230+ if flag(use-c-malloc)
231+ cpp-options: -DUSE_C_MALLOC
232+
225233 ghc-options: -Wall
226234 -Wcompat
227235 -Wunrecognised-warning-flags