Skip to content

swiftwasm/swift-dlmalloc

Repository files navigation

swift-dlmalloc

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.

Supported Platforms

Target triplet Supported
wasm32-unknown-none-wasm

Feel free to create a PR to add support for other platforms.

Usage

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.

License

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.

About

SwiftPM package for dlmalloc

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages