[GHC] #9864: Need realloc/resize feature for mallocForeignPtrBytes allocated memory
GHC
ghc-devs at haskell.org
Thu Dec 4 22:07:00 UTC 2014
#9864: Need realloc/resize feature for mallocForeignPtrBytes allocated memory
-------------------------------------+-------------------------------------
Reporter: slomo | Owner: ekmett
Type: feature request | Status: new
Priority: low | Milestone:
Component: Core Libraries | Version: 7.8.3
Keywords: | Operating System:
Architecture: Unknown/Multiple | Unknown/Multiple
Difficulty: Unknown | Type of failure:
Blocked By: | None/Unknown
Related Tickets: | Test Case:
| Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
Hi,
it would be great if there would be something to reallocate or resize the
memory allocated by
- mallocPlainForeignPtrBytes or
- mallocForeignPtrBytes
Currently this is only possible with memory allocated via mallocBytes by
using reallocBytes, but that's using the system's normal
malloc()/realloc() and will not return memory in the GC heap.
My proposal for a reallocForeignPtrBytes would have the same effects as
reallocBytes. I.e.
- if the new size is bigger than the old size, make enough free space
available. This probably might result in copying the previous memory area
to a newly allocated one
- if the new size is smaller than the old size, mark mark the memory area
as smaller. It should not result in immediate copying of the data, but it
would e.g. allow the GC during a compacting phase to release the
additional memory (note: I don't know how the GHC GC works internally)
- if the new size is the same, do nothing
One possible use case for this would be in ByteString. Currently
Data.ByteString.Internal.createAndTrim will copy the completely memory if
the actual size was less than the expected maximum size. This should be
unnecessary and only wastes CPU cycles.
It would also be useful for bindings to native libraries, e.g. for
allocating the output buffer for iconv().
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9864>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list