diff --git a/Makefile.am b/Makefile.am index de6fd67d..8c5592cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -160,6 +160,8 @@ UTIL_FILES = \ matrix.ipp \ memory.cpp \ memory.hpp \ + memory/system.cpp \ + memory/system.hpp \ net/address.cpp \ net/address.hpp \ net/except.cpp \ diff --git a/memory/system.cpp b/memory/system.cpp new file mode 100644 index 00000000..1e679dd1 --- /dev/null +++ b/memory/system.cpp @@ -0,0 +1,39 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright 2015 Danny Robson + */ + +#include "./system.hpp" + +#include "../except.hpp" +#include "../types/casts.hpp" + +#include + +/////////////////////////////////////////////////////////////////////////////// +size_t +util::memory::pagesize (void) +{ + static size_t val; + + if (!val) { + auto res = sysconf (_SC_PAGE_SIZE); + if (res == -1) + errno_error::throw_code (); + + val = sign_cast (res); + } + + return val; +} diff --git a/memory/system.hpp b/memory/system.hpp new file mode 100644 index 00000000..da9259d0 --- /dev/null +++ b/memory/system.hpp @@ -0,0 +1,26 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright 2015 Danny Robson + */ + +#ifndef __UTIL_MEMORY_SYSTEM_HPP +#define __UTIL_MEMORY_SYSTEM_HPP + +#include + +namespace util { namespace memory { + size_t pagesize (void); +} } + +#endif