mirror of
https://github.com/ilyakooo0/streamly.git
synced 2024-10-26 09:59:48 +03:00
Provide a flag to use the C malloc instead of the default GHC malloc
This commit is contained in:
parent
02f7ce0714
commit
9ccf93168b
@ -16,11 +16,12 @@ module Streamly.Memory.Malloc
|
||||
)
|
||||
where
|
||||
|
||||
#define USE_GHC_MALLOC
|
||||
|
||||
-- We use GHC malloc by default
|
||||
|
||||
import Foreign.ForeignPtr (ForeignPtr, newForeignPtr_)
|
||||
import Foreign.Marshal.Alloc (mallocBytes)
|
||||
#ifndef USE_GHC_MALLOC
|
||||
#ifdef USE_C_MALLOC
|
||||
import Foreign.ForeignPtr (newForeignPtr)
|
||||
import Foreign.Marshal.Alloc (finalizerFree)
|
||||
#endif
|
||||
@ -29,13 +30,13 @@ import qualified GHC.ForeignPtr as GHC
|
||||
|
||||
{-# INLINE mallocForeignPtrAlignedBytes #-}
|
||||
mallocForeignPtrAlignedBytes :: Int -> Int -> IO (GHC.ForeignPtr a)
|
||||
#ifdef USE_GHC_MALLOC
|
||||
mallocForeignPtrAlignedBytes =
|
||||
GHC.mallocPlainForeignPtrAlignedBytes
|
||||
#else
|
||||
#ifdef USE_C_MALLOC
|
||||
mallocForeignPtrAlignedBytes size _alignment = do
|
||||
p <- mallocBytes size
|
||||
newForeignPtr finalizerFree p
|
||||
#else
|
||||
mallocForeignPtrAlignedBytes =
|
||||
GHC.mallocPlainForeignPtrAlignedBytes
|
||||
#endif
|
||||
|
||||
-- memalign alignment size
|
||||
|
@ -204,6 +204,11 @@ flag examples-sdl
|
||||
manual: True
|
||||
default: False
|
||||
|
||||
flag use-c-malloc
|
||||
description: Use C malloc instead of GHC malloc
|
||||
manual: True
|
||||
default: False
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Common stanzas
|
||||
-------------------------------------------------------------------------------
|
||||
@ -222,6 +227,9 @@ common compile-options
|
||||
if flag(inspection)
|
||||
cpp-options: -DINSPECTION
|
||||
|
||||
if flag(use-c-malloc)
|
||||
cpp-options: -DUSE_C_MALLOC
|
||||
|
||||
ghc-options: -Wall
|
||||
-Wcompat
|
||||
-Wunrecognised-warning-flags
|
||||
|
Loading…
Reference in New Issue
Block a user