I cannot import malloc/malloc.h to use malloc_size() to see the size of the object. Is this available in Swift , or am I doing it wrong: import malloc/malloc.h
malloc/malloc.h
malloc_size()
Swift
import malloc/malloc.h
Unix / POSIX materials are in the Darwin module.
Darwin
import Darwin let r = rand() qsort_b(buffer, 0, 10, sortFunc)
malloc also present, but it will not bring you much benefit - it returns an opaque pointer.
malloc
You cannot import C headers. To import a C library (or Objective-C infrastructure) into Swift, it must be in a module. I do not know about the module that contains malloc.
Have you studied using bridge header?
Create an .h file named -Bridging-Header-File.h Then specify it in the project build settings (in the "Swift Compiler" section, find "Objective C Bridging Header") with
$(SRCROOT)/<Your-Project-Name>-Bridging-Header.h
Now malloc_size () should be available
Do you want to use "malloc_size"? You do not need to import "malloc.h" for this, assuming that you either enable Foundation or Cocoa.
This works great on the playground:
import Foundation let chars = BytePtr.alloc( 1000 ) let qty_of_bytes_allocated = malloc_size( chars ) println( qty_of_bytes_allocated )