swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

Missing `NSPageSize` and related functions

Open fumoboy007 opened this issue 1 year ago • 2 comments

In the legacy Foundation module, there are a few useful memory-related functions:

Are they coming to the new FoundationEssentials module?

fumoboy007 avatar Jun 19 '24 07:06 fumoboy007

We likely won't want to bring these static functions as-is into swift-foundation as they don't really fit into Swift nicely. We could instead consider adding page size as an API to, say, ProcessInfo, since it currently has OS-level API such as physicalMemory?

itingliu avatar Jun 21 '24 17:06 itingliu

Good idea!

Perhaps the following names:

  • ProcessInfo.virtualMemoryPageSize
  • BinaryInteger.round(_:toMultipleOf:)
  • BinaryInteger.rounded(_:toMultipleOf:)

Using the rounding APIs would look like

var bytes = …
bytes.round(.up, toMultipleOf: ProcessInfo.processInfo.virtualMemoryPageSize)

Not sure if the rounding APIs should live in Foundation though or somewhere else.

fumoboy007 avatar Jun 21 '24 19:06 fumoboy007