apple / swift-foundation

The Foundation project
Apache License 2.0
2.28k stars 135 forks source link

Missing `NSPageSize` and related functions #691

Open fumoboy007 opened 2 weeks ago

fumoboy007 commented 2 weeks ago

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

Are they coming to the new FoundationEssentials module?

itingliu commented 2 weeks ago

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?

fumoboy007 commented 2 weeks ago

Good idea!

Perhaps the following names:

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.