File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -253,4 +253,25 @@ T move(T)(scope ref return T from) {
253
253
*/
254
254
void copyTo (T)(ref T from, ref T to) {
255
255
__copy(from, to);
256
+ }
257
+
258
+ /**
259
+ Returns `bytes` aligned to a multiple of `alignment`.
260
+ */
261
+ pragma (inline, true )
262
+ size_t alignSize (size_t bytes, size_t alignment) {
263
+ return bytes+ (bytes% alignment);
264
+ }
265
+
266
+ /**
267
+ Aligns `bytes` to the closest memory page boundary.
268
+ If page-size is unknown, aligns to increments of `fallback`.
269
+
270
+ Returns:
271
+ New byte count aligned to page size.
272
+ */
273
+ size_t alignToPage (size_t bytes, size_t fallback=4096 ) {
274
+ import numem.core.system : sysGetPageSize;
275
+ size_t pageSize = sysGetPageSize();
276
+ return alignSize (bytes, pageSize == 1 ? fallback : pageSize);
256
277
}
You can’t perform that action at this time.
0 commit comments