This is a SwiftPM package for dlmalloc which is a general-purpose memory allocator written by Doug Lea. Typically, this package is helpful when you need a memory allocator implementation for Embedded Swift applications.
| Target triplet | Supported |
|---|---|
| wasm32-unknown-none-wasm | ✅ |
Feel free to create a PR to add support for other platforms.
Add the following dependency to your Package.swift file:
dependencies: [
.package(url: "https://github.com/swiftwasm/swift-dlmalloc", from: "0.1.0"),
]Then, add dlmalloc as a dependency for your target:
.executableTarget(
name: "Examples",
dependencies: [
.product(name: "dlmalloc", package: "swift-dlmalloc"),
]
)Finally, import dlmalloc module in your Swift code:
import dlmalloc
public func main() {
let ptr = dlmalloc.malloc(8)!
ptr.storeBytes(of: 42, as: Int.self)
print("malloc(8) = \(ptr)\n")
print("*(\(ptr)) = \(ptr.load(as: Int.self))\n")
dlmalloc.free(ptr)
}See Examples directory for more working examples.
This package is licensed under the MIT license. See LICENSE for more info.
Portions of this software are based on the work of Doug Lea and others. See NOTICE for more info.