-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use specific implementation to get available host memory on MacOS #2597
base: develop
Are you sure you want to change the base?
Changes from 2 commits
7133d78
2c10b6a
6f1f3c1
b9d17f1
b75e9b4
fa12329
8064c87
c513af2
8f0287a
fef0ea9
267844a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef GET_AVAILABLE_MEMORY_HPP | ||
#define GET_AVAILABLE_MEMORY_HPP | ||
|
||
#include <sys/stat.h> | ||
#if defined __MACH__ | ||
#include <sys/types.h> | ||
#include <sys/sysctl.h> | ||
|
||
#include <mach/host_info.h> | ||
#include <mach/mach_host.h> | ||
#include <mach/task_info.h> | ||
#include <mach/task.h> | ||
#endif | ||
|
||
namespace geos | ||
{ | ||
/** | ||
* @brief Retieves current available memory on host | ||
* @return the available memory in bytes. | ||
*/ | ||
static inline size_t getAvailableMemory() | ||
{ | ||
#if defined(__APPLE__) && defined(__MACH__) | ||
int mib[6]; | ||
mib[0] = CTL_HW; | ||
mib[1] = HW_PAGESIZE; | ||
|
||
int pagesize; | ||
size_t length; | ||
length = sizeof( pagesize ); | ||
if( sysctl( mib, 2, &pagesize, &length, NULL, 0 ) < 0 ) | ||
{ | ||
fprintf( stderr, "getting page size" ); | ||
} | ||
|
||
mach_msg_type_number_t count = HOST_VM_INFO_COUNT; | ||
|
||
vm_statistics_data_t vmstat; | ||
if( host_statistics( mach_host_self(), HOST_VM_INFO, ( host_info_t ) &vmstat, &count ) != KERN_SUCCESS ) | ||
{ | ||
fprintf ( stderr, "Failed to get VM statistics." ); | ||
} | ||
|
||
return vmstat.free_count * pagesize; | ||
#else | ||
GEOS_ERROR_IF( percent > 100, "Error, percentage of memory should be smallerer than -100, check lifoOnHost (should be greater that -100)" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied here by accident? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. |
||
return (size_t)sysconf( _SC_AVPHYS_PAGES ) *(size_t) sysconf( _SC_PAGESIZE ); | ||
#endif | ||
} | ||
} | ||
|
||
// remove these definitions from mach/boolean.h that can conflict with GEOS code (eg. InputFlags::FALSE) | ||
#undef TRUE | ||
#undef FALSE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you instead encapsulate this implementation and all system-specific includes in a separate translation unit ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change that, I tend to avoid commiting to LvArray as it is another project but another translation unit would be cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe indicate in the function name that this is for host/system memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.