stack_utils.h 1.1 KB

123456789101112131415161718192021222324252627
  1. #pragma once
  2. #include "stack_common.h"
  3. namespace NCoro::NStack {
  4. /*! Actual size of allocated memory can exceed size in pages, due to unaligned allocation.
  5. * @param sizeInPages : number of pages to allocate
  6. * @param rawPtr : pointer to unaligned memory. Should be passed to free() when is not used any more.
  7. * @param alignedPtr : pointer to beginning of first fully allocated page
  8. * @return : true on success
  9. */
  10. bool GetAlignedMemory(size_t sizeInPages, char*& rawPtr, char*& alignedPtr) noexcept;
  11. /*! Release mapped RSS memory.
  12. * @param alignedPt : page-size aligned memory on which RSS memory should be freed
  13. * @param numOfPages : number of pages to free from RSS memory
  14. */
  15. void ReleaseRss(char* alignedPtr, size_t numOfPages) noexcept;
  16. /*! Count pages with RSS memory
  17. * @param alignedPtr : pointer to page-aligned memory for which calculations would be done
  18. * @param numOfPages : number of pages to check
  19. * @return : number of pages with RSS memory
  20. */
  21. size_t CountMapped(char* alignedPtr, size_t numOfPages) noexcept;
  22. }